in reply to How to FTP with Timeout?

And the Perl part of your question is ...?

Replies are listed 'Best First'.
Re^2: How to FTP with Timeout?
by Anonymous Monk on Nov 10, 2011 at 20:48 UTC

    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

      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;

      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