Re: general retry function
- From: konfera@xxxxxx (Ing. Branislav Gerzo)
- Date: Wed, 28 Sep 2005 19:07:26 +0200
Wiggins d'Anconia [Wd], on Tuesday, September 27, 2005 at 17:51
(-0600) contributed this to our collective wisdom:
Wd> You haven't shown us what you have tried, or where it failed, only
Wd> suggested something about eval and recursive subs, which neither of
Wd> which should be pertinent here. Show us your attempts...
ok, thanks to both for ideas, I sum all of code shown, so I came with
this:
sub ftpupload {
my $config = shift;
# defaults
$config->{retries} = $cfg->{ftp_retries} || 5;
$config->{file} = "$Bin/$config->{template}.html";
my $try = 0;
while ( $try < $config->{retries} ) {
$try++;
print "Uploading ($try/$config->{retries})...\n";
sleep 1;
eval {
my $ftp = Net::FTP->new($config->{ftphost}, Debug => 0)
or die "Cannot connect to $config->{ftphost}: $@";
$ftp->login( $config->{ftpuser}, $config->{ftppass} )
or die "Cannot login ", $ftp->message;
$ftp->cwd( $config->{ftprdir} )
or die "Cannot change working directory ", $ftp->message;
$ftp->put( $config->{file}, "index.html" )
or die "put failed ", $ftp->message;
$ftp->quit;
};
$@ ? print $@ : return 1;
}
print "Failed after $try attempt(s)\n";
return 0;
}
--
...m8s, cu l8r, Brano.
[Recent studies show that recent studies are meaningless.]
.
- References:
- general retry function
- From: Ing. Branislav Gerzo
- Re: general retry function
- From: Wiggins d'Anconia
- general retry function
- Prev by Date: REGEX help with substitute
- Next by Date: Anonymous Reference Question
- Previous by thread: Re: general retry function
- Next by thread: RE: general retry function
- Index(es):