How can I fetch a remote file in php over ssh and return file directly to the browser response without creating a copy of the file on the webserver

后端 未结 2 1334
野趣味
野趣味 2021-01-14 04:38

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

2条回答
  •  佛祖请我去吃肉
    2021-01-14 05:02

    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.

提交回复
热议问题