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