尝试连接sftp服务器与ssh2,但脚本永远运行没有任何错误


Try to connect a sftp server with ssh2 but the script runs forever without any error

我尝试使用ssh2连接到sftp服务器,但似乎php陷入循环。打开错误报告。

我的代码:

$connection = ssh2_connect('my-server.url', 22);
var_dump($connection);
if (ssh2_auth_password($connection, 'username', 'password'))
{
    echo "Authentication success";
    if( ssh2_scp_recv($connection, "/throw_me_an_error/", "/somewhere/" ) )
    {
        echo "file recived";
    }
    else
    {
        echo "error";
    }
}
else 
{
    echo "Authentication failure";
}

生成如下输出:

resource(7) of type (SSH2 Session)
Authentication success

但是一旦脚本试图运行ssh2_scp_recv,它就会卡住并永远运行而没有任何失败。我尝试了现有和不存在的文件。每次都是相同的结果——脚本在循环中运行。

它不仅仅是ssh2_scp_recv,即使我尝试ssh2_exec或其他一些需要在服务器上写或读的方法,它会卡住。

这是怎么回事?

谢谢!

使用phpseclib(一个纯PHP SSH实现)可能会更幸运。