As pointed out, unless there is a precalculated md5 of the file published at the remote end that you can compare your locally calculated value against, calculating an md5 locally doesn't buy you anything.
For a simplistic check, but one that will detect common errors like ascii-v-binary tranfers and partial transfers, use the size method of NET::Ftp to get the remote size of the file and compare that against the local size after transfer. It won't detect in-transit corruption nor deliberate replacements, but then neither will a local MD5 without something reliable to compare against.
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [d/l] |
Very good point. I think I will write a daemon that does MD5 for me via TCP/IP and then do the FTP having the MD5 of the remote file before the transfer. SSH is a good idea as well. I will now just have to decide on the quickest. I have POE server in mind - that will be quick enough ... Will post the script here when done.
| [reply] |
use strict;
use warnings;
use Net::FTP;
use Digest::MD5 qw(md5 md5_hex md5_base64);
my ($ftp, $host, $user, $pass, $handle, $dir, $fname, $hash);
$host = "ftp.mysite.com";
$user = "user";
$pass = "pass";
$dir = "/www/htdocs";
$fname = "robots.txt";
$ftp = Net::FTP->new($host, Debug => 0);
$ftp->login($user, $pass) || die "Bad login";
$ftp->cwd($dir) || die "Unable to change directories";
$ftp->get($fname) || die "Unable to download file";
$ftp->quit;
open($handle, $fname);
$_ = join '', <$handle>;
close($handle);
$hash = md5_hex($_);
print $hash;
You might want something more advanced that gets a directory list, queues all the files, downloads each one and hashes it, and requeues files that fail to download (up to x number of tries per file), but this should get you started. I don't feel like writing a whole application right now :) | [reply] [d/l] |
Keep in mind that successfully ftping a file doesn't guarantee that it'll have the same checksum at the source and destination. If you ftp in ASCII mode, ftp will convert line endings for you (which I consider a good feature). This will destroy your scheme.
thor
The only easy day was yesterday
| [reply] |
| [reply] |
Hmm. I guess the simplest thing to do then would be connect via ssh, ask for a directory of files, then FTP over just the ones updated since the last run. | [reply] |