KianTern has asked for the wisdom of the Perl Monks concerning the following question:

Hi all.
I'm starting to write a script that will act like a daemon and will constantly update my local machine from 4-5 ftp servers. I want check that every file I've downloaded was downloaded correctly.I know I can compare the size of remote and local files, but I'd prefer something more accurate like md5 hash. Is there a way to get a some sort of hash sum from the remote server?
Thanks in advance

Replies are listed 'Best First'.
Re: Check files downloaded from ftp
by jrsimmon (Hermit) on Dec 02, 2007 at 14:24 UTC
    Unless the ftp server provides the md5 hashes, I don't think there's any way you can create them on the server (which is really what you're talking about). If the files aren't too large, and you really want to be sure about their integrity, you could pull each file twice. You would still want to compare the file size to the size on the server. That check combined with a the comparison of multiple downloaded files should be pretty reliable.
Re: Check files downloaded from ftp
by fenLisesi (Priest) on Dec 02, 2007 at 14:29 UTC
    Does the remote server provide such a checksum, perhaps as a similarly named file in the same directory? If so, download that, too, and compare its contents with the checksum that you will generate locally of your downloaded version. If not, is the remote server under your control? If not, can you ask the managers of the remote server to provide such checksums?

    For md5, see Digest::MD5

Re: Check files downloaded from ftp
by graff (Chancellor) on Dec 02, 2007 at 19:30 UTC
    Bear in mind that checking the md5 hash (and the file size) would be appropriate and meaningful only for "binary mode" ftp transfers, as opposed to "text mode", where LF/CRLF conversion is applied during transfer. Text-mode transfers could systematically change file sizes (by adding or removing CR's next to LF's), depending on the particular server and client in a given transfer.

    This is not much of an issue these days -- nearly all ftp transactions are done in binary mode by default now (and usually, ftp tends to be the tool of choice mainly for stuff that is intrinsically non-text). Still, if files are arriving with different sizes than you expect, this is a factor you should check on.

Re: Check files downloaded from ftp
by KianTern (Acolyte) on Dec 03, 2007 at 08:20 UTC
    Thanks for your help guys. I guess I'll do the file size check. And I just discovered that the file will be zips so I'll also do zip test (unzip -t or if I'll find a module to do it).