By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,303 Members | 1,245 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,303 IT Pros & Developers. It's quick & easy.

Stop and Resume Download

P: 162
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() page. I think this is uesfully just not complete for what i need.
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);
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.
Mar 2 '08 #1
Share this Question
Share on Google+
5 Replies

P: 162
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.
Mar 2 '08 #2

P: 162
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.
Mar 5 '08 #3

P: 162

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

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,

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?
Mar 5 '08 #4

P: 162
Still looking for info on this subject. thanks.
Feb 1 '09 #5

Expert 5K+
P: 5,058
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").
Feb 1 '09 #6

Post your reply

Sign in to post your reply or Sign up for a free account.