in reply to Re: How to FTP with Timeout?
in thread How to FTP with Timeout?

Okay. With

use Net::FTP; $ftp = Net::FTP->new("some.host.name", Debug => 0); $ftp->login("anonymous",'-anonymous@'); $ftp->cwd("/pub"); $ftp->get("that.file"); $ftp->quit;

Is there any way to put a time limit on the actual file transfer?

Thanks again.

John Bobinyec

Replies are listed 'Best First'.
Re^3: How to FTP with Timeout?
by priyaviswam (Sexton) on Nov 11, 2011 at 04:26 UTC

    Try the option TimeOut in the constructor. By default this option will take as 120 check the link "http://perldoc.perl.org/Net/FTP.html"

    use Net::FTP; $ftp = Net::FTP->new("some.host.name", Debug => 0, Timeout => 300); $ftp->login("anonymous",'-anonymous@'); $ftp->cwd("/pub"); $ftp->get("that.file"); $ftp->quit;

Re^3: How to FTP with Timeout?
by zentara (Cardinal) on Nov 11, 2011 at 15:41 UTC
    This is untested but you could try to put an eval-alarm combination in there to time the get. Something like:
    #!/usr/bin/perl use warnings; use strict; use Net::FTP; $ftp = Net::FTP->new("some.host.name", Debug => 0); $ftp->login("anonymous",'-anonymous@'); my $timeout = 60; my $time; eval { local $SIG{ALRM} = sub { die "timeout!" }; alarm $timeout; $ftp->cwd("/pub"); $ftp->get("that.file"); $ftp->quit; $time = alarm 0; } if ($@) { if ( $@ =~ /timeout/ ) { #do something } else { #do something else for other failures } } else { print "External call finished in " . ( $timeout - $time ) . " seco +nds\n"; }

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh