phpsshssh2

Issue while copying a file from remote server to local server


I'm trying to copy a few dynamic files from a remote server to a local server using PHP ssh2_connect. Below is the code :

$connection = ssh2_connect('XXX.XXX.XX.x', 8288);
ssh2_auth_password($connection, 'root', 'abcd');
ssh2_scp_recv($connection, $absolute_remote_file_name, $absolute_local_path);

Below are the errors coming:

ssh2_scp_recv(absolute_local_path) : failed to open stream: Is a directory in
ssh2_scp_recv(): Unable to write to local file in

How can I overcome these errors and make it possible to copy/tranfer files from remote to local server.


Solution

  • Issue has been identified and its in the below mentioned block of code.

    ssh2_scp_recv($connection, $absolute_remote_file_name, $absolute_local_path);
    

    We were mentioning destination as directory and assuming file from source(what so ever is the name of the file) will automatically transferred to destination directory with same name as source file name. But instead of giving $absolute_local_path(/var/temp/transferred/file/) we have to give exact name which we want so instead of $absolute_local_path we have to mention name of destination file(/var/temp/transferred/file/t1.csv).