我无法使用 php 中的 ssh2_auth_password 连接到我的服务器 sftp,但如果我使用 FileZilla,则此方法有效。这是我的代码:

I can not connect to my server sftp with ssh2_auth_password in php , but this work if I use FileZilla. This is my code :

$connection = ssh2_connect('sftp://xx.xx.xx.xx', 22) or die ('fail');
if (ssh2_auth_password($connection, 'user', 'password')) {

  echo "Authentication Successful!\n";

} else {

  die('Authentication Failed...');

}


// my result is: fail ;

Filezilla,我认为在功能上与 php 没有任何关系,因为它没有编码。

我建议你检查这个answer

编辑:Also check this from the php manual, sftp connections.

如果这对你有用,请告诉我,

汤姆

您不需要输入 sftp://。只是IP应该没问题。

另外请为 Stack Overflow 正确格式化代码。

来源:http://php.net/manual/en/function.ssh2-connect.php