oop - Resume abandoned downloads with php ftp? -


Is there a way to resume a broken download via an FTP connation installed with php? Could php resume a broken download?

Yes, it can use the ftp_fget optional $ resumepos parameter () function.

Example:

  $ remote_file_name = "/test.txt"; $ Local_file_name = "test.txt"; $ Ftp_server = "ftp.your.server"; $ Username = "Anonymous"; $ Password = "my @ email"; $ Ftp_stream = ftp_connect ($ ftp_server); $ Result = ftp_login ($ ftp_stream, $ username, $ password); If ((! $ Ftp_stream) || (! $ Result)) {echo "FTP connection failed \ n"; } Else {echo "connected to ftp \ n"; } If (file_exists ($ local_file_name)) {$ resume_pos = filesize ($ local_file_name); } And {$ resume_pos = 0; } $ Local_file_handle = fopen ($ local_file_name, "w"); $ Result = ftp_fget ($ ftp_stream, $ local_file_handle, $ remote_file_name, FTP_BINARY, $ resumepos); Fclose ($ local_file_handle); Ftp_close ($ ftp_stream);  

You can use the ftp_size () function to see if a file needs to be restarted or not, but it is not supported on all FTP servers so that you Have to check for that.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

Visual Studio 2005: How to speed up builds when a VSMDI is open? -

booting ubuntu from usb using virtualbox -