in reply to Re: Net::FTP and
in thread Net::FTP and 'Illegal PORT command'

OK with DEBUG set to 1 the relevant output is:

Net::FTP=GLOB(0x82456bc)<<< 220 ProFTPD 1.2.4 Server (ProFTPD Human Ge +nome Project Server) [hgw3] Net::FTP=GLOB(0x82456bc)>>> user anonymous Net::FTP=GLOB(0x82456bc)<<< 331 Anonymous login ok, send your complete + email address as your password. Net::FTP=GLOB(0x82456bc)>>> PASS .... Net::FTP=GLOB(0x82456bc)<<< 230- Net::FTP=GLOB(0x82456bc)<<< Net::FTP=GLOB(0x82456bc)<<< This is the UCSC Genome Project ftp site. Net::FTP=GLOB(0x82456bc)<<< All transactions are logged. Net::FTP=GLOB(0x82456bc)<<< Net::FTP=GLOB(0x82456bc)<<< 230 Anonymous access granted, restrictions + apply. Net::FTP=GLOB(0x82456bc)>>> CWD /goldenPath/05apr2002/chromosomes/ Net::FTP=GLOB(0x82456bc)<<< 250-This directory contains the NCBI assem +bled sequence for the Net::FTP=GLOB(0x82456bc)<<< April 5, 2002 Genbank freeze in separate +files for each Net::FTP=GLOB(0x82456bc)<<< chromosome in a zipped Fasta format. Net::FTP=GLOB(0x82456bc)<<< 250 CWD command successful. Net::FTP=GLOB(0x82456bc)>>> PASV Net::FTP=GLOB(0x82456bc)<<< 227 Entering Passive Mode (128,114,50,183, +199,10). Net::FTP=GLOB(0x82456bc)>>> PORT 192,168,1,125,172,80 Net::FTP=GLOB(0x82456bc)<<< 500 Illegal PORT command. get(chr5.zip) failed: 500: Illegal PORT command. Net::FTP=GLOB(0x82456bc)>>> QUIT Net::FTP=GLOB(0x82456bc)<<< 221 Goodbye.
The same chunk from the SunOS machine:

Net::FTP=GLOB(0xfcd34)<<< 220 ProFTPD 1.2.4 Server (ProFTPD Human Geno +me Project Server) [hgw5] Net::FTP=GLOB(0xfcd34)>>> user anonymous Net::FTP=GLOB(0xfcd34)<<< 331 Anonymous login ok, send your complete e +mail address as your password. Net::FTP=GLOB(0xfcd34)>>> PASS .... Net::FTP=GLOB(0xfcd34)<<< 230- Net::FTP=GLOB(0xfcd34)<<< Net::FTP=GLOB(0xfcd34)<<< This is the UCSC Genome Project ftp site. Net::FTP=GLOB(0xfcd34)<<< All transactions are logged. Net::FTP=GLOB(0xfcd34)<<< Net::FTP=GLOB(0xfcd34)<<< 230 Anonymous access granted, restrictions a +pply. Net::FTP=GLOB(0xfcd34)>>> CWD /goldenPath/05apr2002/chromosomes/ Net::FTP=GLOB(0xfcd34)<<< 250-This directory contains the NCBI assembl +ed sequence for the Net::FTP=GLOB(0xfcd34)<<< April 5, 2002 Genbank freeze in separate fi +les for each Net::FTP=GLOB(0xfcd34)<<< chromosome in a zipped Fasta format. Net::FTP=GLOB(0xfcd34)<<< 250 CWD command successful. Net::FTP=GLOB(0xfcd34)>>> PASV Net::FTP=GLOB(0xfcd34)<<< 227 Entering Passive Mode (128,114,50,185,21 +6,226). Net::FTP=GLOB(0xfcd34)>>> PASV Net::FTP=GLOB(0xfcd34)<<< 227 Entering Passive Mode (128,114,50,185,21 +6,227). Net::FTP=GLOB(0xfcd34)>>> RETR chr5.zip Net::FTP=GLOB(0xfcd34)<<< 150 Opening ASCII mode data connection for c +hr5.zip (59604544 bytes).

Two PASV commands?

Bukowski - aka Dan (dcs@black.hole-in-the.net)
"Coffee for the mind, Pizza for the body, Sushi for the soul" -Userfriendly

Replies are listed 'Best First'.
Re: Re: Re: Net::FTP and
by amphiplex (Monk) on Jul 17, 2002 at 11:25 UTC
    I guess that setting
    Passive=>1
    when creating the ftp object should fix your problem. At least it did for me.

    If it works, could someone explain why exactly ?

    ---- amphiplex
      I've covered this previously for a couple of others experiencing the same problem - When connecting to a FTP server, two socket streams are used for communications - The first is the control connection initiated by your FTP client between which the FTP client and server exchange commands and replies (TCP socket 21). The second is a full-duplex connection over which data is transferred in a specified mode and type. The data transferred may be part of a file, an entire file or a listing of files within a directory. Typically, this data port is the port adjacent to the control port (TCP socket 20). In general, it is the FTP server's responsibility to initiate and maintain the data connection.

      According to the output supplied, it appears that the poster of this question is attempting to connect to the FTP from a machine with a private class address - This host address, along with the preferred socket for data communications, are sent to the server via the PORT command. I would suspect that the poster is connecting to the FTP server host through a network firewall or layer of address translation and as such, the data connection from the server to your machine is failing because the FTP server is unable to reach your private machine.

      The means by which to fix this is to switch to passive FTP transfer mode via the PASV command - This command changes the default behaviour of data port negotiation, shifting the onus for responsibility for data port establishment and maintenance back to the client. This allows the client to control its only data connection through the network firewall or translation layer, allowing normal FTP communications to occur. eg.

      use Net::FTP; # Passive mode can be set with object initiation my $ftp = Net::FTP->new( $hostname, Debug => 1, Passive => 1 ) or die +$!; $ftp->login( $user, $password ); # Or with $object->pasv; $ftp->pasv;

      Further information on this topic can be found in RFC documents File Transfer Protocol, Requirements for Internet hosts - communication layers and Firewall-Friendly FTP.

       

        What confuses me is that setting Passive and using pasv() result in different commands beeing sent.
        When using pasv(), the PORT command is still beeing sent:

        debug using Passive=>1:
        Net::FTP=GLOB(0x829328c)<<< 230 Logged in anonymously. Net::FTP=GLOB(0x829328c)>>> CWD /z2/privacy/crypto/etext^M Net::FTP=GLOB(0x829328c)<<< 250 "/z2/privacy/crypto/etext" is new cwd. Net::FTP=GLOB(0x829328c)>>> PASV^M Net::FTP=GLOB(0x829328c)<<< 227 Entering Passive Mode (192,35,244,50,2 +32,18) Net::FTP=GLOB(0x829328c)>>> RETR ug.ps.gz^M Net::FTP=GLOB(0x829328c)<<< 150 Data connection accepted from 62.116.6 +2.82:44135; transfer starting for ug.ps.gz (73235 bytes). Net::FTP=GLOB(0x829328c)<<< 226 Transfer completed.

        Debug using pasv():
        Net::FTP=GLOB(0x8293280)<<< 230 Logged in anonymously. Net::FTP=GLOB(0x8293280)>>> PASV^M Net::FTP=GLOB(0x8293280)<<< 227 Entering Passive Mode (192,35,244,50,2 +32,0) Net::FTP=GLOB(0x8293280)>>> CWD /z2/privacy/crypto/etext^M Net::FTP=GLOB(0x8293280)<<< 250 "/z2/privacy/crypto/etext" is new cwd.
        Net::FTP=GLOB(0x8293280)>>> PORT 62,116,62,82,172,96^M Net::FTP=GLOB(0x8293280)<<< 200 PORT command successful.
        Net::FTP=GLOB(0x8293280)>>> RETR ug.ps.gz^M Net::FTP=GLOB(0x8293280)<<< 150 Opening ASCII mode data connection for + ug.ps.gz (73235 bytes). Net::FTP=GLOB(0x8293280)<<< 226 Transfer completed.

        ---- amphiplex

        Edit by tye to change PRE tags to CODE tags

      Amphiplex, respect. I will ++ this tomorrow and yes :

      $ftp = Net::FTP->new($destination, Debug => 1, Passive =>1) || die "Co +uldn't connect! $!\n";

      does indeed fix the problem under Linux.

      Bukowski - aka Dan (dcs@black.hole-in-the.net)
      "Coffee for the mind, Pizza for the body, Sushi for the soul" -Userfriendly

Re: Re: Re: Net::FTP and
by valdez (Monsignor) on Jul 17, 2002 at 13:30 UTC
    Net::FTP=GLOB(0x82456bc)>>> PORT 192,168,1,125,172,80

    I think the error is here, you can't use a private address for the PORT command...

    Ciao, Valerio

Re: Re: Re: Net::FTP and
by gbarr (Monk) on Jul 17, 2002 at 18:59 UTC
    You get the error because the PORT command is following a PASV command. They should not happen together.

    You chopped off the top of the dubug output, what version of Net::FTP do you have installed ?

    As someone else noticed you have a private IP, is the server on the other side of a firewall ?

    If yes, you must use passive mode, as the remote server will not be able to connect back to you. But that is a different problem.