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

I want to write an ftp client that could be able to continue downloads should the connection be broken. I know of programs that do this already such as Getright, Gozilla etc but I want the experience of writing something myself :) I've been investigating this and came across Net::FTP restart ( WHERE ) method. Would this be the right this to use and if so does anyone have any help they could offer as to how I would proceed ?
Thanks Chris

Replies are listed 'Best First'.
Re: FTP client that continues downloads
by echo (Pilgrim) on Aug 31, 2001 at 16:01 UTC
    Use Net::FTP::get($remote_file, $local_file, $offset) where offset is the byte count at which you want to transfer to resume. For example if you have received a partial file, you can check how many bytes you have downloaded with -s $file, and then use that number as the offset argument to Net::FTP::get(). The remaining of the file will be appended to the local file.
      Just a little coment about -s $file... it doesn't work as it should if you're running Windows (the file size is only updated when you close the file handle).

      acid06
      perl -e "print pack('h*', 16369646), scalar reverse $="
Re: FTP client that continues downloads
by MZSanford (Curate) on Aug 31, 2001 at 14:12 UTC
    For sending data, i have used the Net::FTP append function, along with seek(), but i have still come up with currupt data in some cases. But, usually, it works ok. With getting data, i have never used it, but an interesting problem ... hmmm.
    can't sleep clowns will eat me
    -- MZSanford
Re: FTP client that continues downloads
by Cine (Friar) on Aug 31, 2001 at 17:30 UTC
    You should be aware that it is not unusual for data in the end of a file, whose transfer went wrong is corrupt.
    So after you have figured out how large your already downloaded file is (with -s) subtract 4k (works best IMO) to throw away data that is likely to be corrupt. And then resume your file transfer.

    T I M T O W T D I
Re: FTP client that continues downloads
by princepawn (Parson) on Aug 31, 2001 at 17:09 UTC
    However , an FTP server is not required to support resumable downloads, so be sure to check what their response to your REST is.

    visit faqs.org/rfc for the FTP RFC to verify this.