简体   繁体   English

从 ftp 下载文件时 perl 超时

[英]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.我尝试下载大文件,这需要使用 perl 从 ftp 链接下载大量时间。 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解决方案:谢谢@Chris Doyle 我在我的 perl 文件"not ftp.pm file"更改了超时值谢谢

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.问题似乎是由于您的 Perl 脚本中缺少错误处理。

Surely you have something like this at your perl script:你的 perl 脚本肯定有这样的东西:

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.请注意这是在.../perl/lib/Net/FTP.pm 之外,因为 FTP.pm 是您用来访问 ftp 的第三方模块( Kind of library ),我建议您不要碰它以避免以后出现便携性问题。

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.通常在 FTP.pm 内达到超时并进入或打印“出现错误”条件,但在某些情况下,服务器/客户端只是不同步并且 FTP.pm 只是抛出一个未处理的异常.

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.在这里,您可以使用eval将代码包装起来,捕获异常并根据需要进行处理。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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