Stop and Resume Download

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cesarcesar
Forum Contributor
Posts: 111
Joined: Mon Oct 18, 2004 3:28 pm

Stop and Resume Download

Post by cesarcesar »

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.
If you previously downloaded a file before (like a huge web log), and just want to get the remaining portion, do this:

Code: Select all

 
$local_file_size = filesize($local_file_path);
$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.
cesarcesar
Forum Contributor
Posts: 111
Joined: Mon Oct 18, 2004 3:28 pm

Re: Stop and Resume Download

Post by cesarcesar »

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.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: Stop and Resume Download

Post by s.dot »

I have never dealt with a situation like this, so my advice may not be worth advocating, but..

I think the more appropriate solution would be to either break the file up into manageable chunks (.rar's perhaps), or advise the downloader to have a download manager installed.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
cesarcesar
Forum Contributor
Posts: 111
Joined: Mon Oct 18, 2004 3:28 pm

Re: Stop and Resume Download

Post by cesarcesar »

thanks for your advice scottayy. I do prefer to have it just down load and resume if needed. Your suggestions create a whole mess of extra steps.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: Stop and Resume Download

Post by s.dot »

I think if you want to go with your solution, having a look at the content range header might do some good.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply