in reply to Net::FTP Question.
I'm guessing that you've got this code in a loop, and run it once per client. If this is the case, take a look at the below code. It uses an eval block to catch any errors per each client, and if it fails, it will print a notice and per runrig's suggestion, retry two more times before giving up and moving on to the next client.
#!/usr/bin/perl use warnings; use strict; use Net::FTP; my $user='steve'; my $password='...'; my $file='re.pl'; my @clients = qw(localhost example.com); for my $client (@clients){ for (1..3){ my $ftp; eval { $ftp=Net::FTP->new( $client, Timeout => 2, Passive => 1 ) or die "Could not Connect.\n"; $ftp->login ($user, $password); $ftp->binary; $ftp->put($file) or die "Error Uploading.\n"; print "$client done on attempt $_\n"; $ftp->quit; }; last if ! $@; print "$client broke on attempt $_\n"; } } __END__ $ ./ftp.pl localhost done on attempt 1 example.com broke on attempt 1 example.com broke on attempt 2 example.com broke on attempt 3
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Net::FTP Question.
by FeistyLemur (Acolyte) on Aug 13, 2015 at 19:49 UTC |