Great question, you are dealing with 2 transaction here. The first transaction puts the file into a location on your web server. This uses HTTP as a transport via a POST method (also likely the slowest part of this transaction).
Once the initial client side upload is complete the file will be stored on your web server where a S/FTP script can now transfer.
Reading the comment below what you wanted was to transfer the file using FTP from the client side, and that's a perfectly viable solution. However this is the current process you implemented.
Your process currently.
- User A uploads a file via HTTP using a web page you host.
- User A waits until file upload has completed before closing his browser.
- File is saved in the directory path specified in the upload script.
- S/FTP script reads the file and initiates a connection with a foreign S/FTP server and begins transferring the file to that server.
If step 4 is redundant then the S/FTP script is not required at all unless what you wanted was to transfer via S/FTP from the client.
Your intention.
- User A uploads a file via S/FTP using a browser based S/FTP client.
- User A waits for file upload to complete.
- File is saved in the directory path specified in the upload script.
In the comments you mentioned possibly implementing a Flex solution. Here are some resources I found that might help.
Flex FTP based client
Flex based FTP Client question on Stack Exchange
Implement a S/FTP client on the server side with PHPSecLib.
SFTP.php on Gist (for line numbers and highlighting)
Original PHPSec SFTP.php
I copied the original via the Sourceforge site to Gist so you can use the line numbers as a guide. The SFTP library expects either a full path to file (i.e /tmp/somefilehere ) or a valid PHP file resource. Like the one returned by fopen $fp = @fopen('/tmp/somefilehere', 'rb');
see line 1132 on gist for an example.
Once authenticated the transfer will be pretty quick compared to the initial upload. Your Server is likely in a data centre with much more bandwidth so file transfers are much faster.
You probably want to initiate a S/FTP transaction via your web browser. Its possible just not with conventional scripting languages like PHP / Python or Ruby. You can S/FTP from the browser with Flash, Flex or Java and probably some Windows technologies too.