From: Gary Wright Date: 2011-09-19T10:56:44+09:00 Subject: Re: FTP ports On Sep 18, 2011, at 9:18 PM, Reese Chappuis wrote: > The connect method suggestion didn't work. And I just noticed another thing- > the port number in the error keeps changing. In one test it was 11742, and > in the next it was 11728. ftp is an old protocol and has a somewhat unique architecture. The command connection is initiated by the client towards port 21. When an actual file transfer is needed, the *client* begins listening on a local port that is picked by the OS (sometimes called an ephemeral port). The client then tells the server which port number was allocated via the control connection (11742 then 11728 in your instance). At this point the *server* initiates a data connection to the client towards the port number that was allocated by the client system. This is called 'active mode' in the protocol spec. This is where problems usually occur because many firewalls or administrative policies block that incoming TCP connection from the server to the client. An alternative is to tell ftp to use 'passive mode'. In this mode, the *server* picks an ephemeral port, tells the client what it picked via the command connection, and then the client establishes the data connection towards the server. In this mode the two TCP connections are both outbound from the client and can often negotiate any firewalls as necessary. You may be experiencing problems with either of these modes based on the firewall policies between the client and the server. You can set passive mode on as follows (based on quick look at net/ftp): ftp = Net::FTP.new(hostname) ftp.passive = true # make sure you do this, defaults to false ftp.login uname, pass ftp.puttextfile filename, rfilename ftp.close Gary Wright