tags:

views:

100

answers:

1

I'm building an FTP client using Net::FTP. The documentation states that the new constructor has a Host option which can be a reference to an array with hosts to try in turn. I don't seem to be able to get this to work. I'm using ActivePerl under Windows XP. Here's my code:

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

And here's the error message:

Can't connect: Net::FTP: Bad hostname 'Host'
+6  A: 

At first glance, it looks like all you have to do is to provide a reference:

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

but there seems to be something flaky with Net::FTP here. I am not sure if anyone has tested this. I don't have time to debug it right now, but I would just recommend doing:

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;

Update: I checked the source code for Net::FTP->new and there does not seem to be any checks for an array reference passed. This seems to be a case of the code and docs not matching each other.

Bug report filed.

Update:

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
Sinan Ünür
Hmm, still can't get it to work. When I try:my @try_these = ("turing.unh.edu", "euler.unh.edu");my $ftp = Net::FTP->new(Host => \@try_these)or die "Can't connect: $@\n";I get:Can't connect: Net::FTP: Bad hostname 'ARRAY(0x1829da4)'
I don't know how to file a bug report. This is actually my first day using Perl. I think it would be best if you did it.
@Larry, OK will do.
Sinan Ünür
Filing a report is easy. Go to rt.cpan.org and file a report for Net-FTP.
brian d foy