elentz Posted September 24, 2017 Share Posted September 24, 2017 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); ?> Quote Link to comment Share on other sites More sharing options...
requinix Posted September 24, 2017 Share Posted September 24, 2017 Depends on what sort of indicator you want to use. Quote Link to comment Share on other sites More sharing options...
elentz Posted September 24, 2017 Author Share Posted September 24, 2017 Some type of bar would be fine. Right now all I have is the end message. Quote Link to comment Share on other sites More sharing options...
requinix Posted September 24, 2017 Share Posted September 24, 2017 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 Quote Link to comment Share on other sites More sharing options...
elentz Posted September 24, 2017 Author Share Posted September 24, 2017 It is that complicated? Quote Link to comment Share on other sites More sharing options...
requinix Posted September 24, 2017 Share Posted September 24, 2017 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. Quote Link to comment Share on other sites More sharing options...
elentz Posted September 25, 2017 Author Share Posted September 25, 2017 Ok thanks. I will have to study up on Ajax Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.