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

I'm trying to automatically upload a data file to my server, from my clients, every 5 seconds
I tried net::ftp code, but it never makes it past the stor command.

My code is here:
$ftpobj = Net::FTP -> new ("server.com",Debug =>1,Timeout=>60); $ftpobj -> login("user","pass"); $ftpobj -> binary; $ftpobj -> cwd ("/Users/a/code/perl/ftptest"); $ftpobj -> delete ("/Users/a/code/perl/ftptest/testfile.txt"); $ftpobj -> put ("/Users/a/code/perl/testfile.txt","/Users/a/code/perl/ +ftptest/testfile.txt"); $ftpobj -> quit; print "file size ",-s "testfile.txt"," bytes\n";

When I use console ftp to send the file to the same server, it uploads inside of a second or two. Using the net::ftp lib, it's timing out. I must be doing something wrong as it's only 23 bytes. The Debug message is below:
Net::FTP>>> Net::FTP(2.75) Net::FTP>>> Exporter(5.567) Net::FTP>>> Net::Cmd(2.26) Net::FTP>>> IO::Socket::INET(1.26) Net::FTP>>> IO::Socket(1.27) Net::FTP>>> IO::Handle(1.21) Net::FTP=GLOB(0x889f84)<<< 220 server.com FTP server (lukemftpd 1.1) r +eady. Net::FTP=GLOB(0x889f84)>>> user a Net::FTP=GLOB(0x889f84)<<< 331 Password required for a. Net::FTP=GLOB(0x889f84)>>> PASS .... Net::FTP=GLOB(0x889f84)<<< 230- Net::FTP=GLOB(0x889f84)<<< Welcome to Darwin! Net::FTP=GLOB(0x889f84)<<< 230 User a logged in. Net::FTP=GLOB(0x889f84)>>> TYPE I Net::FTP=GLOB(0x889f84)<<< 200 Type set to I. Net::FTP=GLOB(0x889f84)>>> CWD /Users/a/code/perl/ftptest Net::FTP=GLOB(0x889f84)<<< 250 CWD command successful. Net::FTP=GLOB(0x889f84)>>> DELE /Users/a/code/perl/ftptest/testfile.tx +t Net::FTP=GLOB(0x889f84)<<< 250 DELE command successful. Net::FTP=GLOB(0x889f84)>>> ALLO 23 Net::FTP=GLOB(0x889f84)<<< 202 ALLO command ignored. Net::FTP=GLOB(0x889f84)>>> PORT 69,82,120,222,214,103 Net::FTP=GLOB(0x889f84)<<< 200 PORT command successful. Net::FTP=GLOB(0x889f84)>>> STOR /Users/a/code/perl/ftptest/testfile.tx +t Net::FTP=GLOB(0x889f84): Timeout at ftp.pl line 10 Net::FTP=GLOB(0x889f84)>>> QUIT Net::FTP=GLOB(0x889f84)<<< 425 Can't build data connection: Operation +timed out. file size 23 bytes

Replies are listed 'Best First'.
Re: Net::FTP question. Better way?
by dave_the_m (Monsignor) on Dec 08, 2004 at 13:03 UTC
    Looks like a firewall issue. You need to put the ftp connection into passive mode, $ftpobj->pasv

    Dave.

      Fixed.
      Many thanks
      The author of the lib wrote me back. Pasv command only helps the command immediately following it.
      Needed to do this and add Passive
      $ftpobj = Net::FTP -> new ("server.com",Debug =>1,Timeout=>60,Passive => 1);
        Thanks. Adding "Passive => 1" to my Net::FTP usage solved a similar issue for us today.

        Oddly enough I hadn't had that issue on RHEL5 using Perl 5.8.8 base and older Net::FTP module. We moved to RHEL6 which uses a 5.10.1 base and it had a slightly newer Net::FTP module. I'm guessing the older module defaulted to Passive but the newer one doesn't.