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

I recently installed package libnet to my WIN NT running ActivePerl. Running the FTP script below doesn't echo and doesn't seem to work, although no visible error is generated. I watched the script begin, execute and end while Netstat showed the connection to the remote host just beginning. How can I dump progress of ftp to a log so I can diagnose what's happening?
# # FTP Test use Net::FTP; $ftp = Net::FTP->new("www.somedomain.org"); $ftp->login("user","password"); $ftp->cwd("/pages"); $ftp->get("defhome.htm"); $ftp->quit; #testftp.pl

Replies are listed 'Best First'.
Re: use of ftp in libnet package
by lhoward (Vicar) on May 10, 2000 at 06:52 UTC
    You should check the return codes after each call to a Net::FTP method (actually, the code I present below should work for just about any Net:: module that comes with libnet, not just Net::FTP). See the below code:
    use Net::FTP; $ftp = Net::FTP->new("www.somedomain.org"); check_net_err($ftp); $ftp->login("user","password"); check_net_err($ftp); $ftp->cwd("/pages"); check_net_err($ftp); $ftp->get("defhome.htm"); check_net_err($ftp); $ftp->quit; sub check_net_err{ my $net=shift; if(!defined $net){ die "Net:: object not defined $!"; }else{ if((!$net->ok())||($net->code() >= 400)){ die "Net:: error ".$net->code()." : ".$net->message(); } } }
    You can set the Debug flag on the Net::FTP->new call and get a trace of the session dumped to STDERR.
    my $ftp = Net::FTP->new("www.somedomain.org",Debug=>1);
    example output of Net::FTP w/ Debug=>1
    Net::FTP: Net::FTP(2.40)
    Net::FTP:   Exporter
    Net::FTP:   Net::Cmd(2.12)
    Net::FTP:   IO::Socket::INET(1.24)
    Net::FTP:     IO::Socket(1.25)
    Net::FTP:       IO::Handle(1.21)
    
    Net::FTP=GLOB(0x81f20e4)<<< 220 www.somedomain.org FTP server (Version wu-2.6.0(1) Thu Oct 21 12:27:00 EDT 1999) ready.
    Net::FTP=GLOB(0x81f20e4)>>> user someusername
    Net::FTP=GLOB(0x81f20e4)<<< 331 Password required for someusername.
    Net::FTP=GLOB(0x81f20e4)>>> PASS ........
    Net::FTP=GLOB(0x81f20e4)<<< 230 User someusername logged in.
    Net::FTP=GLOB(0x81f20e4)>>> CWD /pages
    Net::FTP=GLOB(0x81f20e4)<<< 550 /pages: No such file or directory.
    Net:: error 550 : /pages: No such file or directory.
    Net::FTP=GLOB(0x81f20e4)>>> QUIT
    Net::FTP=GLOB(0x81f20e4)<<< 221-You have transferred 0 bytes in 0 files.
    Net::FTP=GLOB(0x81f20e4)<<< 221-Total traffic for this session was 269 bytes in 0 transfers.
    Net::FTP=GLOB(0x81f20e4)<<< 221-Thank you for using the FTP service on www.somedomain.org.
    Net::FTP=GLOB(0x81f20e4)<<< 221 Goodbye.
    
    
    You may want to check out the earlier post Trapping errors from NET::Ftp for some other approaches.
Re: use of ftp in libnet package
by Khürt (Initiate) on Dec 17, 2000 at 02:10 UTC
    The module supports a debug flag that will dump to STDERR. Also the module has an object method "message()" that returns the text message returned from the last command. My suggestion is to modify your scripts as follows.
    use Net::FTP;
    eval '$ftp = new Net::FTP("www.somedomaind.org",Debug => 1);' or die("Connection failed.\n");
    $ftp->login("username","password") or die($ftp->message());
    $ftp->cwd("/pages") or die($ftp->message());
    $ftp->get("defhome.htm") or die($ftp->message());
    $ftp->quit() or die($ftp->message());