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

Wise Monks,

I have been trying for a good hour now to figure out why this code is not working. I think it may be my ignorance of FTP coupled with my first use of Net::FTP.

The code:

#!/usr/bin/perl -w use strict; use Net::FTP; my ($ftp, $destination, $username, $password, $filename, $path); $destination="genome.ucsc.edu"; $username="anonymous"; $password="me\@there.com"; $path="/goldenPath/05apr2002/chromosomes/"; $filename="chr5.zip"; $ftp = Net::FTP->new($destination, Debug => 0) || die "Couldn't connec +t! $!\n"; $ftp->login($username,$password) || die "Couldn't log in! $!\n"; $ftp->cwd($path) || die "couldn't cwd! $!\n"; $ftp->get($filename) || die "get($filename) failed: " . $ftp->code() . + ": " . $ftp->message(); $ftp->quit;
This dies with the error:
[dswan@ashtaroth GUP]$ perl ftp.pl get(chr5.zip) failed: 500: Illegal PORT command.
I am assuming this has something to do with a failure to use the pasv/port options of Net::FTP - I have tried ftp->pasv() and ftp->port() (leaving blank, and specifying a port). Its not a firewall issue as I can happily use a command line client to make it work - and grab the file.

Yours, in bewilderment,

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

Title edit by tye

Replies are listed 'Best First'.
Re: Net::FTP and
by amphiplex (Monk) on Jul 17, 2002 at 11:08 UTC
    I would recommend turning up the Debug-Volume, this should give you and us valuable information.

    ---- amphiplex
      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

        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
        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

        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.

OS related problem?
by Bukowski (Deacon) on Jul 17, 2002 at 11:05 UTC
    Now I'm even more confused. This code does not work on my RedHat 7.3 machine, but works fine on the SunOS 5.8 machine.

    /me is off to investigate

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