Search code examples
phpscplibssh2

Can you use ssh2_scp_recv in php to get a remote directory?


I am trying to use

ssh2_scp_recv($connection, '/remote/directory', '/local/directory'); 

to get a remote directory, but I am getting the error:

Warning: ssh2_scp_recv(): Unable to receive remote file in /some-php-file.php on line 2.

It works if I use ssh2_scp_recv to get a single file.

Is this function supposed to work on directories? It wasn't clear from reading the docs.


Solution

  • You cannot use ssh2_scp_recv to get a directory. You can, however, use scandir using ssh2.sftp:// wrapper.

    http://php.net/manual/en/wrappers.ssh2.php

    Check this gist for an example credit for code to the gist owner danielbwa