Search code examples
phplinuxwindowscp

ssh2 scp via php from win do unix does not work


I'm currently stuck with a weird issue: When copying a file from a windows remote machine to local unix one, it's failing due to not found file on remote.

Error:

Warning: ssh2_scp_recv(): Unable to receive remote file 

php code

ssh2_scp_recv($connection, "textexample", "nexText.txt");

usual scp is working:

scp user@host:textexample textexample

As I was trying to send (programatically) via ssh2_scp_send it was working but file on remote host was named 'textexample' (with those quotes). So assumption is that there somewher windows is screwing it up ;)

On Windows side after ssh in the user has cmd session. But afaik this should not do anything here (and usual SCP is working anyways).

Any ad hoc ideas?

Best, Bent


Solution

  • To make sure nobody else is stumbling upon that nasty-ness here :)

    I solved it with the suggested lib from @Chris Haas in comment above:

    phpseclib.com

        $sftp = new SFTP($remoteHost, $port);
        if ($sftp->login($username, $password)) {
            echo "Password authentication successful\n";
    
            // Trying to download one file
            if ($sftp->get('textexample', 'textexample')) {
                echo "Copied one file successfully\n";
                return true;
            }
            return false;
        }
    
        echo "Password authentication not successful\n";
        return false;
    

    Does the trick!