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

Hello All PERL master (monks) out there ! I need some perl wisdom here !! I want to write a perl script which will allow file download resuming, I have written a script to do this what it does is that it reads every char from the target file and increments a variable and then writes it to a file ! and if the connection breaks the file is still there and when the next time the user tries to download it see if the download data file exist and if it does it reads it goes to the location in it and againg send the file and so on ... to read chars i have used sysread(); i used seek to write data to data file !! is seems to work but there must be a better way !! so please help me Thanx Ahmad axidpk.hypermart.net

Replies are listed 'Best First'.
Re: Web based resumer !!
by merlyn (Sage) on Mar 14, 2001 at 18:29 UTC
    At the level at which you are asking questions, I'm not sure you'll hear this answer, but, here goes...

    Besides all of that, you'll also need to tell the server to send only the data that you don't have. Otherwise, it'd be simpler just to move your file out of the way and start over.

    See "Re: Re: Re: download part of remote files" for a snippet of code that uses the Range: header to ask for the last 128 bytes. You'll need to do something similar to ask for the bytes that you don't have. The response may or may not be a "partial content" response: if it is, you can append it to your existing data; otherwise, you'll need to replace your existing data. Oh, and you'll have to verify that the modification date of the response is the same as your original response. I hope you saved the original modification date somewhere.

    What you ask is do-able, but not easy. And not at the level you are asking questions. Good luck.

    -- Randal L. Schwartz, Perl hacker

Re: Web based resumer !!
by toadi (Chaplain) on Mar 15, 2001 at 13:54 UTC
    Maybe to make it easier is:

    On *nix machines there will be always the wget. I love that command. Use it for everything. FTP, WWW and it has resume and recursive downloading. Use system to execute it!

    --
    My opinions may have changed,
    but not the fact that I am right

      the script is in fact a CGI script and it sends files to STDOUT and keeps the track using a counter now some one told me that Apache tells very late when the connection is expired, so if that is the way my script will not work good, it will cause data loss so how to work that out ?? how to detect from Perl if the Apache has disconnected
      Ahmad Mushtaq
      ahmadpak@hotmail.com
      http://axidpk.hypermart.net