I feel this deserves a question since StackOverflow seems to be missing out on this topic.
I want to use SFTP using PHP with a progress indicator
I like the progress indicators . However, this time I want to do something completely different. I want to do the following with PHP, and it looks a lot more complicated than the last:
- Download via SFTP (via SSH?)
- Give the user a visible indication of the loading process.
- Enable pause and continue downloading
Think FileZilla , but in a browser built with PHP. I do not want to hack Apache or add any Apache motifs.
Options for actual download
There are many questions here , here and here for the basic SFTP download.
This document is a PHP SSH2 extension (which I am currently using - you install it via pecl) and an alternative PHPSecLib , which I do not use, but may take a look later.
My interface makes it easy to switch I / O - the coding of the interface, not the implementation, etc.
This is great, but they just do the actual download and what it is.
Boot process
PHP has a really interesting stream_notification_callback , which you can read more about here .
This looks great and was a promising step until someone studied the PHP source code and found that, unfortunately, SSH2 / SFTP does not allow integration with this
Thanks to hek2mgl for learning this.
The idea with stream_notification_callback was to send a notification of the current download size each time data is retrieved; therefore giving the data needed to calculate the percentage using the current loaded amount and the total file size. But this does not happen with SSH2 and SFTP ...
What about pausing / continuing?
In my opinion, this would be the most difficult to accomplish. Loading data into a temporary file would be possible ... Here's what I managed to dig: http://ee.php.net/manual/en/function.fread.php#84115 - But integrating such code with a progress indicator seems crazy.
Finally
There is also cURL, however I have not seen pausing / resuming downloads as much as possible using SFTP. Correct me if I am wrong.
So, how do I go about integrating the above requirements in a browser using PHP? Forget about the client side, just get the data in the browser, so the recommendations for doing this will be great.