2

最近我遇到了这个库,它允许我连接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安装,可以进行连接。我已经尽我所能。有人可以帮我吗?

4

1 回答 1

0

CodeIgniter-SSH2 库正在使用 php 的原生函数 ssh2_connect(),它是基于 sftp 的安全 shell 登录,基本上连接到端口 22。尝试更改端口:

$connection = ssh2_connect("123.45.67.890", 22);
于 2013-03-06T04:09:01.117 回答