Actually, we have similar scripts to this. We have a
threshold of so many errors before the script croaks.
Basically, the script attempts to ftp to the file. If it
fails, it calls a "redo" and keeps trying until there is
success or the max number of failures is exceeded. Here
are a couple of snippets from the code, to at least let
you see how we do it.
sub get_files {
# ftp files from remote server
while (1) {
$ftp = Net::FTP->new("$From_Host", Debug => 0);
$ftp->login("$From_User","$From_Pass") || do { &print_
+ftp_error; redo; };
$ftp->cwd("$From_Dir");
(@dir_files = $ftp->dir) || do { &print_ftp_error; red
+o; };
$ftp->quit;
last;
}
sub print_ftp_error {
# Error handling proc
$save = $ftp->error;
$ftp->quit;
print STDERR "ftp error: $save\n";
print_to_log("ftp error: $save\n");
if (++$ftp_errors{"$save"} >= $Max_ftp_Errors) {
print STDERR "\n\nExceeded maximum number of ftp error
+s. Exiting!!!\n";
print_to_log("\n\nExceeded maximum number of ftp error
+s. Exiting!!!\n");
system("$Notify_Proc \"ftpfiles.pl Exceeded maximum nu
+mber of ftp errors. Please check $Log_File.\" 2>&1 > /dev/null");
rename "$Log_File", "$Log_File.$year.$mon.$mday\_$hour
+.$min";
exit 1;
} else {
#
# Give the ftp server a 60 second grace period to get
# it's act together.
#
sleep 60;
}
}
birdbrane
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.