最近我遇到了这个库,它允许我通过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
,并且已准备好进行连接。我尽我所能。有人可以帮帮我吗?
答案 0 :(得分:0)
CodeIgniter-SSH2库正在使用php的本机函数ssh2_connect(),这是基于sftp的安全shell登录,并且基本上连接到端口22.尝试更改端口:
$connection = ssh2_connect("123.45.67.890", 22);