-1

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

8
  • What have you done to try to solve the problem yourself? Have you looked at the Net::FTP documentation, perhaps searching for "timeout"? search.cpan.org/~shay/libnet-3.08/lib/Net/FTP.pm
    – Mort
    Apr 26, 2016 at 16:35
  • 1
    if you look at the documentation for the word timeout the first thing you see is Timeout - Set a timeout value in seconds (defaults to 120) so if file is taking longer than 120 seconds to download then you need to change the timeout value before starting the ftp Apr 26, 2016 at 16:39
  • @Mort I open ftp.pm in my computer and look for timout variable it written as: 'Timeout => $ftp->timeout' I want to know how to change it "the syntax? and what is the suggested value. I don't want to play in something I don't understand.
    – sara
    Apr 26, 2016 at 16:45
  • 2
    you set it as part of the creating of the ftp object. i would suggest you show your code if you want people to help, you should not be changing the ftp.pm module its self. the module allows you to specify a timeout value from your own code Apr 26, 2016 at 16:47
  • 1
    then show how you call it. there will have to be some line of perl code that loads the FTP module. Normally in perl code it would be something like my $ftp = Net::FTP->new("localhost", Timeout => 600); here i have set timeout as 600 which will now overwrite the default 120, so you can change timeout value by passing it as an argument to the object when you create it Apr 26, 2016 at 16:52

1 Answer 1

0

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();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.