Connecting Tech Pros Worldwide Forums | Help | Site Map

Stop and Resume Download

Familiar Sight
 
Join Date: Apr 2006
Posts: 133
#1: Mar 2 '08
I have some scripts that when initiated by a link click will FTP a 1G+ file from a secure server to another server using ftp_get(). Once ftp_get() is complete i then user Content Headers to open a "save as" dialog box. (working good to this point).

Since the files are so large there will be times when a user loses connection or something else that interrupts the download happens. Now what i need is to be able to "finish" the download from the point it was left off.

I have some ideas about how this should be done, but not sure how to code it or if im even going the right direction. My thinking is to -

1. get filesize of trasfering file.
2. check to see if file resides in location being "saved as..".
3. if file does not exist, then download normal.
4. if does exist then, check the server file size against the local file size. if they are different, start the download from the left off point merging the two files some how together on the clients local machine.

I did pluck this out of the ftp_get() php.net page. I think this is uesfully just not complete for what i need.
Quote:
If you previously downloaded a file before (like a huge web log), and just want to get the remaining portion, do this:

Expand|Select|Wrap|Line Numbers
  1. $local_file_size = filesize($local_file_path);
  2. $get_result = ftp_get($conn_id, $local_file_path, $remote_file_path, FTP_BINARY, $local_file_size);
  3.  
This same code works regardless of wether the local file exists already or not. You should first test to make sure the local file is not bigger than the remote file.
Thanks for all the help in advance.

Familiar Sight
 
Join Date: Apr 2006
Posts: 133
#2: Mar 2 '08

re: Stop and Resume Download


I think the resumepos parameter of ftp_get couple with the startpos parameter of ftp_put should handle this?

I have looked into this but there is so little documentation on the "resumepos" and "startpos" parameters and how they work. I'm not sure how to use.
Familiar Sight
 
Join Date: Apr 2006
Posts: 133
#3: Mar 5 '08

re: Stop and Resume Download


How/When is $_SERVER['HTTP_RANGE'] or $_ENV['HTTP_RANGE'] set? I am working on a resume download script that requires the HTTP_RANGE to be set... but no matter what i do i cant find how/when its set. Thanks.
Familiar Sight
 
Join Date: Apr 2006
Posts: 133
#4: Mar 5 '08

re: Stop and Resume Download


http://tools.ietf.org/id/draft-ietf-http-range-retrieval-00.txt

This link explains a lot about HTTP_RANGE. It still leaves out two important points...

Quote:
The server will send this header only for documents for which it will
be able to satisfy the byte range request, e.g. for PDF documents, or
images, which can be partially reloaded if the user interrupts the
page load, and image gets only partially cached.
What types of files satisfy the byte range request? also,

Quote:
The Request-Range header is simply ignored
by a server that does not support it, and it will send the entire
document as a response.
How do i know if my server supports it?
Familiar Sight
 
Join Date: Apr 2006
Posts: 133
#5: Feb 1 '09

re: Stop and Resume Download


Still looking for info on this subject. thanks.
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,754
#6: Feb 1 '09

re: Stop and Resume Download


You can obviously not force this upon the client, but if his download manager supports it, it should pass the HTTP_RANGE header to you, specifying which part of the file it wants to download.

Then you would send that range, passing along the Content-Range header, indicating the range you are sending.

I Googled those headers and found a nice example in the comments on the fread manual entry (Search for the poster "Edward Jaramilla").
Reply