简体   繁体   中英

perl timeout when downloading file from ftp

I try to download huge file which takes a lot of time downloading from ftp link using perl. I got:

Timeout at C:/Strawberry/perl/lib/Net/FTP.pm

what does this means and how to solve it?

Thanks

Solution: Thanks @Chris Doyle I change the timeout value in my perl file "not ftp.pm file" Thanks

You can increase the timeout, but it is important that if the timeout is reached again and your server/client are out of sync, it might throw the same error you got the first time, again.

It seems that the issue is due a lack of error handling in your Perl Script instead.

Surely you have something like this at your perl script:

my $ftp = Net::FTP->new( $myhost, Timeout => 10, Debug => 1 );
...
$ftp->get($myfile) or print "Got an error";
$ftp->quit();

Please notice this is out of .../perl/lib/Net/FTP.pm , since the FTP.pm is the third party module ( Kind of library ) you are using to reach the ftp, I suggest you to not touch it to avoid portability issues later on.

Normally the timeout is reached inside the FTP.pm and it goes to the or print "Got an error" condition, but there are some cases, that the Server/Client just get out of sync and the FTP.pm just throws an unhandled exception.

This exception will NOT go to the or print "Got an error" condition, therefore you need to catch it and handle it as any other languages.

Here you can use eval to wrap it up the code, catch the exception and handle it as you need.

For example:

my $ftp = Net::FTP->new( $myhost, Timeout => 10, Debug => 1 );
...
eval {$ftp->get($myfile) or print("Can't get file $myfile") };
if ($@ =~ /Timeout/) {
    print "Got a timeout Issue: $@";
}

$ftp->quit();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM