H
Henry Law
I expect I'm doing something wrong, but Googling for [perl "Net::FTP"
timeout problem] shows nothing; nor does perldoc -q ftp. Can someone
point me in the right direction?
(ActiveState Perl, "v5.8.7 built for MSWin32-x86-multi-thread").
I use Net::FTP to pass files around my internal network. Occasionally I
specify a host that isn't up, at which point Net::FTP hangs for a long
time before giving up. "Set a timeout," I thought, but using the
Timeout=>nnn option on the login operation seems to have no effect -
though the documented default of 120 seconds isn't in operation either.
Here's a sample program which should work with any server that
supports anonymous FTP.
------------------------- sample -----------------------------
#! /usr/bin/perl
use strict; use warnings;
use Net::FTP;
my ($host,$timeout) = @ARGV;
exit 0 unless defined $host;
$timeout = 120 unless defined $timeout;
my $start_time = time;
print "Logging in to $host with timeout $timeout seconds\n";
my $ftp = Net::FTP->new( $host, Timeout=>$timeout );
unless (defined $ftp) {
print "Timed out in ",(time - $start_time)," seconds\n";
print "Session to '$host' failed\n";
exit 0;
}
$ftp->login( 'anonymous', '(e-mail address removed)' );
my $cwd = $ftp->pwd();
print "Current directory at $host is '$cwd'\n";
$ftp->quit();
print "Session finished\n";
-------------------------- sample output follows -----------------
F:\User\PC\NFBack>tryit.pl neptune 5
Logging in to neptune with timeout 5 seconds
Current directory at neptune is '/'
Session finished
F:\User\PC\NFBack>tryit.pl uranus 5
Logging in to uranus with timeout 5 seconds
Timed out in 21 seconds
Session to 'uranus' failed
F:\User\PC\NFBack>tryit.pl uranus 1000
Logging in to uranus with timeout 1000 seconds
Timed out in 21 seconds
Session to 'uranus' failed
----------------------------- end ---------------------------------
timeout problem] shows nothing; nor does perldoc -q ftp. Can someone
point me in the right direction?
(ActiveState Perl, "v5.8.7 built for MSWin32-x86-multi-thread").
I use Net::FTP to pass files around my internal network. Occasionally I
specify a host that isn't up, at which point Net::FTP hangs for a long
time before giving up. "Set a timeout," I thought, but using the
Timeout=>nnn option on the login operation seems to have no effect -
though the documented default of 120 seconds isn't in operation either.
Here's a sample program which should work with any server that
supports anonymous FTP.
------------------------- sample -----------------------------
#! /usr/bin/perl
use strict; use warnings;
use Net::FTP;
my ($host,$timeout) = @ARGV;
exit 0 unless defined $host;
$timeout = 120 unless defined $timeout;
my $start_time = time;
print "Logging in to $host with timeout $timeout seconds\n";
my $ftp = Net::FTP->new( $host, Timeout=>$timeout );
unless (defined $ftp) {
print "Timed out in ",(time - $start_time)," seconds\n";
print "Session to '$host' failed\n";
exit 0;
}
$ftp->login( 'anonymous', '(e-mail address removed)' );
my $cwd = $ftp->pwd();
print "Current directory at $host is '$cwd'\n";
$ftp->quit();
print "Session finished\n";
-------------------------- sample output follows -----------------
F:\User\PC\NFBack>tryit.pl neptune 5
Logging in to neptune with timeout 5 seconds
Current directory at neptune is '/'
Session finished
F:\User\PC\NFBack>tryit.pl uranus 5
Logging in to uranus with timeout 5 seconds
Timed out in 21 seconds
Session to 'uranus' failed
F:\User\PC\NFBack>tryit.pl uranus 1000
Logging in to uranus with timeout 1000 seconds
Timed out in 21 seconds
Session to 'uranus' failed
----------------------------- end ---------------------------------