最近我遇到了这个库,它允许我连接ssh
到远程机器。(这个案例,一个假123.45.67.890
的。图书馆是
shukydvir。
但是,我遵循了overview
选项卡中给出的说明,如下所示:
public function deploy_test()
{
$params = array(
'hostname' => "123.45.67.890",
'port' => 23,
'username' => "username",
'password' => "password"
);
if(!($con = $this->ssh->connect($params))) {
echo json_encode("fail: unable to establish connection\n");
}
else {
echo json_encode("helloworld");
}
}
当我回到网页时:
fail: unable to establish connection
因此,厌倦了这一点,我安装了ssh2
库,并重新启动了我的服务器:
public function deploy_test() {
$connection = ssh2_connect("123.45.67.890", 23);
if(!$connection) {
echo json_encode('Connection failed');
}
ssh2_auth_password($connection, "username", "password");
$stream = ssh2_exec($connection, "ls -l");
stream_get_blocking($stream, true);
$output = "";
while($line = fgets($stream)) {
$output .= $line;
}
echo json_encode($line);
}
结果并不令人鼓舞:
<p>Severity: Warning</p>
<p>Message: ssh2_connect(): Unable to connect to 123.45.67.890 on port 23</p>
<p>Filename: controllers/automation.php</p>
<p>Line Number: 70</p>
但是,当我从test.php
文件中执行相同的脚本时,我得到:
02/13/2013 10:41 PM .
02/13/2013 10:41 PM ..
02/13/2013 10:41 PM 952 FreeSSHd.lnk
1 File(s) 952 bytes
2 Dir(s) 55,343,263,744 bytes free
另一台服务器已freSSHD
安装,可以进行连接。我已经尽我所能。有人可以帮我吗?