Why does SFTP via PHP fail, but succeeds in FileZi

2019-07-08 11:01发布

问题:

In PHP, I cannot even get the SFTP connection to work. I have tried to use the native SFTP functionality (ssh_connect), and it fails to connect. I have also tried to use phpseclib, but it fails as well. Neither of my aforementioned attempts have provided much in the way of log info.

The native code:

if (!function_exists('ssh2_connect')) { 
    echo "dll not loaded properly"; //never see this, so I know it works
    return false;
}
$connection = ssh2_connect('sftp.example.com', 22);
ssh2_auth_password($connection, 'username', 'password');
$sftp = ssh2_sftp($connection);

phpseclib library code:

include('Net/SFTP.php');

$sftp = new Net_SFTP('sftp.example.com');
if (!$sftp->login('username', 'password')) {
    exit('Login Failed');
}

I have also tried to track all of the transactions via Fiddler to see if I at least see a connection being made, and I do see an error in the browser (below) that from googling may mean that a connection was made to the server, but no responses.

[Fiddler] ReadResponse() failed: The server did not return a complete response for this request. Server returned 17139 bytes. 

Why am I able to connect to the URL with the username and password via FIleZilla, but not from within php? Do I need some other DLLs in PHP's /ext folder (e.g. php_openssl.dll, etc.)?

Thanks, Sean