[英]error when trying to connect with sftp
我正在尝试使用sftp类建立连接
我的代码:
$host = 'some ip address';
$username = 'username';
$pass = 'password';
$sftp = new SFTPConnection($host, 22);
$sftp->login($username, $pass);
当我运行此脚本时,出现消息Could not authenticate with username and password
当我使用同一用户并通过sftp传递fileZilla
时,可以,我可以建立连接,但是无法使用脚本
有人知道是什么问题吗?
尝试在login(){}
函数的sftp.php中添加此代码。 然后说出它给出了什么错误:
if (!extension_loaded('ssh2'))
{
throw new Exception("Extension ssh2 has to be loaded to use this class. Please enable in php.ini.");
}
if (! @ssh2_auth_password($this->connection, $username, $password))
throw new Exception("Could not authenticate with username $username " . "and password $password.");
$this->sftp = @ssh2_sftp($this->connection);
if (! $this->sftp)
throw new Exception("Could not initialize SFTP subsystem.");
编辑您的代码以执行以下操作[[有人说我们应该同时通过username_password和hostKeyAuthentication进行身份验证]
-------------------------------
上面的描述表明:
问题在于php扩展,假设您将使用密码或公共密钥进行身份验证。 因此,使用密码进行身份验证会给您带来失败,并可能使您误入歧途(简要说明位于链接中: Must Read )。
$connection = ssh2_connect($host, $port);
ssh2_auth_password($connection, $username, $password);
if (ssh2_auth_pubkey_file($connection, $username, $pubkey, $privatekey)) {
echo "Public Key Authentication Successful";
}
else {
echo 'Public Key Authentication Failed' ;
return false;
}
好的,这是什么问题...
FTP服务器上不允许我的IP地址吗? 现在,当他们将我的IP列入白名单时,一切正常。
谢谢你们的努力。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.