Jump to content

ftp_get status throbber


elentz

Recommended Posts

I have a rude and crude script that I put together that works for my purposes.  I would like to get some type of indicator that shows the progress of the download.  How can I do this?  Thanks Here is my code:

<?php
// connect and login to FTP server
$ftp_username = "firmware";
$ftp_userpass = "password";
$ftp_server = "ftp.myserver.com";
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);

$local_file = "/tftpboot/firmware/400/400firmware.fw";
$server_file = "firmware.fw";
ftp> hash;
// download server file
if (ftp_get($ftp_conn, $local_file, $server_file, FTP_ASCII))
  {
  echo "New Firmware successfully downloaded for the 400.";
  }
else
  {
  echo "Error downloading $server_file.";
  }

// close connection
ftp_close($ftp_conn);
?>

Link to comment
Share on other sites

So in other words you want to have three scripts:

1. One for the page that shows the progress and whatever else

2. One that does the actual FTP operation(s) and is started by #1

3. One called through AJAX that reports on the progress of the operation and is used by #1 to update its progress bar

Link to comment
Share on other sites

Well yeah. Technically you could combine 1+2 (the displayed page can also start the download) or 2+3 (the page doing the download can report its progress back as it goes) but it doesn't decrease the complexity - only move it around, or even make it worse.

It doesn't mean you have to have three separate .php files: there have to be three things executing separately, and whether all the code is in one file or not isn't an issue.

 

So here's the process:

1. You show the #1 page to the user. No progress yet.

2. User clicks a button to start the download, or it starts automatically. Doesn't matter. The process involves an AJAX request to start the #2 script with the download.

3. After that has started, the page periodically checks with the #3 script for the progress of the download. The #2 request is still running but you can't get much information from it.

4. Eventually the #2 request finishes and it returns a response like any other AJAX page would. The #1 page stops calling #3 because the download is complete (be it successfully or not).

 

The #1 page works however you want. The #2 script is basically the code you have there. The #3 script can simply report the size of the local downloaded file, which can be compared to the total file size for progress.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.