CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Net::FTP incomplete downloads

 



vortmax
New User

Apr 23, 2008, 10:40 AM

Post #1 of 3 (353 views)
Net::FTP incomplete downloads Can't Post

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 file....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?

I attached the full code, but the sub in question is below:






Code
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 SNMP, 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 dir


#### 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;
}

Attachments: ftpget.pl (6.18 KB)


KevinR
Veteran


Apr 23, 2008, 11:21 AM

Post #2 of 3 (348 views)
Re: [vortmax] Net::FTP incomplete downloads [In reply to] Can't Post

I don't know what you could do to figure this out. Since there are not a lot of experienced users on this forum answering questions I suggest you ask on www.perlmonks.com and see if one of the members of that forum has some advise to offer. If you get some good advise please post back here.
-------------------------------------------------


vortmax
New User

Apr 23, 2008, 1:00 PM

Post #3 of 3 (345 views)
Re: [KevinR] Net::FTP incomplete downloads [In reply to] Can't Post

Thanks for your advice. I posted it over on the perlmonks board and got a (good) answer.

Their solution was to use the size() method of Net::FTP to get the size of the file before downloading, then once the file was downloaded, check the size of the local file. If they match, then the whole file made it.

While that is a simple and elegant solution, my ftp server for some strange reason does not support the 'size' command.....

So I'll still post back if I figure something else out.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives