在PHP5.3.3(在CentOS和apache2的),我试图通过PHP脚本连接到SFTP。 该代码抓住从构造的按键和服务器的详细信息
function __construct(){
$this->host = 'servername.loc';
$this->port = SFTP_PORT;
$this->auth_user = 'username';
$this->auth_pub = '/data/home/username/.ssh/id_rsa.pub';
$this->auth_priv = '/data/home/username/.ssh/id_rsa';
$this->auth_pass = null;
$this->connection = null;
}
并使用这些信息来创建连接。
private function connect(){
if (!($this->connection = ssh2_connect($this->host, $this->port))) {
$this->response = array('code' => "20",
"message" => "Error connecting to SFTP server.");
return false;
}
if (!ssh2_auth_pubkey_file($this->connection, $this->auth_user, $this->auth_pub,
$this->auth_priv, $this->auth_pass)) {
$this->response = array('code' => "40",
"message" => "Error authenticating to SFTP server with key.");
$this->disconnect();
return false;
}
}
结果我得到的是在电话会议上的错误ssh2_auth_pubkey_file()
错误是:
“ssh2_auth_pubkey_file():认证使用公钥失败的用户名:无效的关键数据,而不是base64编码 ”
有对键的密码,我可以通过CLI SSH使用这些键来手动连接到服务器。
我难倒。 我需要以某种方式编码的钥匙? 建议?