A timeout question using Net::FTP

T

Trudge

I have a script to download files. It checks the remote and local directories, and downloads any new files from the remote location.

Here is part of my code:
my $ftp = Net::FTP->new
(
"ftp.xxx.yy",
Timeout => 3600,
Debug => 0
) or die "Could not connect: $@\n";

My question is, what units are the Timeout option in? The docs don't make it clear, and I'm guessing the units are seconds. Anyone have a definitive answer?
--
 
T

Trudge

Quoth Trudge:










The timeout is passed to IO::Select, so it's in seconds, possibly

fractional.



Ben

Thank you Ben (again) for clearing something up for myself and possibly others. That gives me a starting point.
 
J

J. Gleixner

Idunno, Ben:


$ perltidy safe_post11.pl
Why do we need to see this??
$ perl safe_post11.pl my_ftp
You can make safe_post11.pl an executable so you don't have to type
'perl' every time.
..........
success is 22
$ cat safe_post11.pl
#!/usr/bin/perl -w
use strict;
use 5.010;
use Net::FTP;
use diagnostics;

$| = 1; # Disable output buffering

## usage: perl safe_post11.pl server_name
my $ident = 'my_ftp.txt';
my ($config, $domain);
$config = do($ident);
unless ($config) {
die("read error: $!") if $!;
die("parse error: $@") if $@;
}

$domain = $config->{$ARGV[0]};
die("unknown domain: $ARGV[0]") unless $domain;

# printf("server\t%s\nuser\t%s\npass\t%s\n",
# $domain->{domain},
# $domain->{username},
# $domain->{password});

We don't need to see most of the noise above. Show only the
specific code that describes your problem.
my $ftp = Net::FTP->new( $domain->{domain}, Timeout => 5 ) or die "Can't
connect: $@\n";
$ftp->login( $domain->{username}, $domain->{password} )
or die "Couldn't login\n";
Always include the reason/message. When it fails it might tell you why.
for (1..10) {
print '.';
sleep 1;
}
print "\n";

my @r = $ftp->ls();
my $success = scalar(@r);
print "success is $success\n";
That seems like an odd way to determine success.
# close $ftp;
$

cpan says 120 is the default, but haven't I changed that?

Yes. You don't show the failure that is taking longer than 5
seconds to timeout though.

Using sleep there doesn't do anything to show there's a problem. The
login() will wait for the connection to succeed or fail. The timeout
is how long to wait around for a response, it doesn't have anything to
do with how long it's connected.

If you want to do something with the connection based on elapsed
time, see perldoc -f alarm . Usually that's not needed because
it usually connects and you do what's needed and close the connection,
or you can't connect or the operation times out and you handle the error.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top