Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have a perl script which uses Net::FTP to put a file on a remote server. This script is installed on both a Windows box (Net::FTP v2.65) and a Linux box(Net::FTP v2.75). A problem occurs when the script on the Linux box tries to put a file on a IIS Server on a Win2K box. The login, mkdir and cwd commands work fine but the put command times-out and a zero-length file is present on the remote server. The script on the Windows box runs fine and places the file on the server correctly. The admin guy from the IIS server says that the problem is that the Linux script is not using the correct data port(20) while the Windows script is. I do not specify any data port, only the standard ftp port(21) in my scripts and am at a loss as to why this is happening. Any ideas?? rgds, Conor.

Replies are listed 'Best First'.
Re: Net::FTP port inconsistencies
by dave_the_m (Monsignor) on Feb 18, 2005 at 12:52 UTC
    It's almost certainly a firewall issue, either at the linux oir windows end. Try putting the ftp client into passive mode - that usually resolves most such issues. When not in passive mode, ftp requires a second data conncection to be established from a ramdom port on the server to a random port on the client, which generally gets blocked by stateless firewalls.

    Dave.

      Hi Dave,

      Thanks for your reply. We already use passive mode as indicated by the code below:
      my $ftp = Net::FTP->new($self->{HOSTNAME}, "Firewall" => "", "Port" => 21, "Debug" => 0, "Passive" => 1);
      I just tried creating an FTP connection from the linux command line and I get the same problem, i.e. I can login and move to the relevant directory but the put command times out. Perhaps, this is a setting on the linux server??

      rgds
      Conor

        In passive mode, the data connection is initiated by the cleint, so it is likely to be the firewall on the server which is too strict.

        I'm too sure about the "Firewall" => ""; I'm not sure whether a blank proxy name acts the same as no proxy; you might want to comment out that line and see if it makes any difference (but it probably won't).

        A final suggestion would be to use sftp if possible - it's a lot more firewall friendly!

        Dave.

Re: Net::FTP port inconsistencies
by castaway (Parson) on Feb 19, 2005 at 10:50 UTC
    FTP uses port 20 as its data port, per default. That is, the client should listen on port 20, for the server to send data to. The passive command asks the server to designate a data port, and listen on it, which the client then connects to. (The point being that sometimes the client is behind a firewall or isnt allowed to open ports for listening). See section 3.3 of the RFC.

    If you are using passive (PASV), then neither is using port 20. Possibly the IIS server has problems with passive mode? (Would be odd though) .. Try adding DEBUG => 1 to your ->new call, and gve us the results?

    C.

      Hi castaway,
      Sorry about delay in replying but have been away from desk for a few days

      Changed "DEBUG => 1" as you suggested and the message returned is below: (sorry about all asterisks - i'm a bit paranoid about putting too many details on internet)

      Net::FTP>>> Net::FTP(2.75) Net::FTP>>> Exporter(5.562) Net::FTP>>> Net::Cmd(2.26) Net::FTP>>> IO::Socket::INET(1.25) Net::FTP>>> IO::Socket(1.26) Net::FTP>>> IO::Handle(1.21) Net::FTP=GLOB(0x93767e4)<<< 220 eyesp05 Microsoft FTP Service (Version + 5.0). Net::FTP=GLOB(0x93767e4)>>> user ******** Net::FTP=GLOB(0x93767e4)<<< 331 Password required for ********. Net::FTP=GLOB(0x93767e4)>>> PASS .... Net::FTP=GLOB(0x93767e4)<<< 230 User ******** logged in. Net::FTP=GLOB(0x93767e4)>>> MKD /********************** Net::FTP=GLOB(0x93767e4)<<< 550 /**********************: Cannot create + a file when that file already exists. Net::FTP=GLOB(0x93767e4)>>> CWD /********************** Net::FTP=GLOB(0x93767e4)<<< 250 CWD command successful. Net::FTP=GLOB(0x93767e4)>>> ALLO 13517 Net::FTP=GLOB(0x93767e4)<<< 200 ALLO command successful. Net::FTP=GLOB(0x93767e4)>>> PASV Net::FTP=GLOB(0x93767e4)<<< 227 Entering Passive Mode (**,***,***,***, +13,206). Net::FTP=GLOB(0x93767e4)>>> STOR test20050216b.asp Net::FTP=GLOB(0x93767e4)<<< 425 Can't open data connection.