为什么不在Net :: FTP->新工作中传递Host参数的数组引用?

时间:2009-07-18 22:22:33

标签: perl ftp libnet

我正在使用Net::FTP构建FTP客户端。该文档指出新构造函数具有Host选项,该选项可以是对具有要依次尝试的主机的数组的引用。我似乎无法让这个工作。我在Windows XP下使用ActivePerl。这是我的代码:

@try_these = ("turing.unh.edu", "euler.unh.edu");
$ftp = Net::FTP->new(Host => @try_these)
or die "Can't connect: $@\n";

这是错误信息:

Can't connect: Net::FTP: Bad hostname 'Host'

1 个答案:

答案 0 :(得分:6)

乍一看,看起来你要做的就是提供一个参考:

my $ftp = Net::FTP->new(Host => \@try_these);

但这里似乎有Net::FTP的片状。我不确定是否有人测试过这个。我现在没时间调试它,但我建议你这样做:

my $ftp;
for my $host ( @try_these ) {
    warn "Attempting to connect to '$host'\n";
    $ftp = Net::FTP->new( $host ) and last;
}

die "Could not connect\n" unless $ftp;

更新:我检查了Net::FTP->new的源代码,似乎没有对传递的数组引用进行任何检查。这似乎是代码和文档彼此不匹配的情况。

Bug report提交。

<强>更新

Subject: Re: [rt.cpan.org #48001] Net::FTP->new(Host => $arrayref) does not work 
Date:    Sun, 19 Jul 2009 11:35:14 -0500 
To:      bug-libnet[...]rt.cpan.org 
From:    Graham Barr  [text/plain 147b]
> > Seems like a mismatch between the code and the docs.
> 
> Not sure where that came from in the docs, Net::FTP has never supported an
> array of hosts