I have several CMTS (Cable modem Termination systems) on remote sites that I backup via FTP on a daily basis. My script (below), recursively pulls the server's ip from a database, checks to see if the server is alive via SNMP, starts the FTP session, pulls the files, parses one of them into a database, then tars them in the appropriate folder.
Sometimes when I run this script, it doesn't download the complete file before moving on, but the ftp process doesn't return any sort of error. When I notice this happens, I run a second script that uses the same subs, but only pulls in one site's worth of files....and it doesn't seem to have this issue.
Any thoughts on how to suppress this or to at least catch it so I can attempt the download again?
The subroutine in question is below. I suppressed the entire script because of length but can post it too if needed.
sub getFiles{
### ftp constants ###########
my $ip = @_[0];
my $dir = '/ata00';
my $user = 'xxxxx';
my $pass = 'xxxxx';
my $dbg = 0;
if ($debug) {print "\tConnecting to $ip\n ";
$dbg = 1;
}
if(CMTScheck($ip)){ return 1;} #if CMTS cannot be contacted via SNM
+P, die
$ftp = Net::FTP->new("$ip", Debug => $dbg) or $error=1;
+#initialize connection
if($error){ #if error, quit
print "\tServer is not responding\n";
return 1;
}
##### Login #############
$ftp->login("$user","$pass") or $error=1;
if($error){
print "Username and Password not accepted";
$ftp->quit;
return 1;
}
$ftp->binary; #set binary mode
$ftp->cwd('/ata00'); #change to /ata00 di
+r
#### Retrieve files #########
$ftp->get('dhcpd.con') or $error=1;
if($error){
print "Could not retrieve dhcpd.con...... quitting";
$ftp->quit;
return 1;
}
$ftp->get('smsact.db') or $error=1;
if($error){
print "Could not retrieve smsact.db...... quitting";
$ftp->quit;
return 1;
}
$ftp->quit;
return 0;
}
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.