tags:

views:

302

answers:

5

I have a php-script that uploads files to an ftp server from a location with a very low bandwith, low reliability connection. I am currently using the ftp functions of php.

Sometimes the connection drops in the middle of a transfer. Is there a way to later resume the upload? How can this be done?

Edit: People misunderstood that this is happening from a browser. However, this is not the case. It is a php cli script. So it is about a local file being uploaded to ftp, no user interaction.

A: 

are you meaning you are going to allow user resume upload from you web interface ? is this suit you ? http://www.webmasterworld.com/php/3931706.htm

spencerlim
No, not from a web interface. See my edit on the question.
Peter Smit
please text proper next time but don't waste time and credit of other folk !!sorry for any text that make you feel uncomfortable...
spencerlim
Wasting time of other folk? In my original question I was already clearly talking about uploading from php with the ftp functions. I don't know where you got the idea that it had anything to do with the web interface. That you wasted your time is not my fault.
Peter Smit
+2  A: 

Try getting the remote file's size and then issuing the APPE ftp command with the difference. This will append to the file. See http://webmasterworld.com/forum88/4703.htm for an example. If you want real control over this, I recommend using PHP's cURL functions.

George Edison
Your link is broken, but the idea is indeed what I need. If you repair your link I will happily upvote...
Peter Smit
Silly me! Done and fixed.
George Edison
A: 

ftp_(f)put has a $startpos parameter. You should be able to do what you need using this parameter. (starts the transfer from the file size on your server). However I never used it, so I don't know about the reliability. You should try.

Savageman
Where is this $startpos parameter documented? Is it really starting from that byte at both the client and the remote file?
Peter Smit
If this answer would be expanded, I could change my accepted answer to it and upvote it!
Peter Smit
A: 

just use the filezilla can done everything for you ...i mean the uploading process... it will keep the data and reopen after close you will be able to continue process q...

for automate and tracking , simply use our way...which is git and capistrano there is an option for php try google it...

spencerlim
You haven't read the question. He needs to do this programatically.
George Edison
A: 

I think all the previous answers are wrong. The PHP manage the resume, for that FTP_AUTODESK must be activated, and you have to activate the FTP_AUTORESUME during upload. The code should be something like this :

$ftp_connect = ftp_connect($host, $port);
ftp_set_option ($ftp_connect, FTP_AUTOSEEK, TRUE);
$stream = fopen($local_file, 'r');
$upload = ftp_fput($ftp_connect, $file_on_ftp, $stream, FTP_BINARY, FTP_AUTORESUME);
fclose($stream);
Axel