I am currently using a similar version of the below code to transfer a file from a remote server to my web server and then redirecting to the web server copy of the file in
You can use ssh2_sftp http://php.net/manual/en/function.ssh2-sftp.php ... you must install ssh2 bindings as PECL extension (http://php.net/manual/es/book.ssh2.php)
An example code may be ...
$sftp = ssh2_sftp($connection);
$remote = fopen("ssh2.sftp://$sftp/path/to/file", 'rb');
header( 'Content-type: ......');
while(!feof($remote)){
echo( fread($remote, 4096));
}
I have not tested the code, but it should work.
You can use phpseclib to download the file:
require_once 'Net/SFTP.php';
$connection = new Net_SFTP($remote_server_ip);
if (!$connection->login('username', 'password')) die('Login Error');
// set some appropriate content headers
echo $connection->get($filelink);
Or you can use the ssh2.sftp
wrapper - see SilvioQ's answer for that approach.