【问题标题】:php ssh2 fgets();php ssh2 fgets();
【发布时间】:2012-12-21 10:51:32
【问题描述】:

我尝试在远程主机上打开一个文件并读取它,但我得到的返回值为 1。 也许有人发现了我的错误。

public function get()

        {
            return $stream = file_get_contents("ssh2.sftp".$this->connection."/home/user/logfile.txt");
        }

$this->连接是:

public function __construct($host , $port , $user , $pass )
{
    if(!$this->connection = ssh2_connect($host, $port)) return -1;
    if(ssh2_auth_password( $this->connection, $user, $pass )) return -1;
    return 1;
}

连接也可以,可以发送其他命令,例如 tar ...

【问题讨论】:

    标签: php ssh


    【解决方案1】:

    我可以推荐phpseclib, a pure PHP SFTP implementation吗?它更容易使用并且得到更好的支持。以下是你的做法:

    <?php
    $sftp = new Net_SFTP($host, $port);
    if (!$sftp->login($user, $pass)) {
        exit('bad login');
    }
    echo $sftp->get('/home/user/logfile.txt');
    ?>
    

    如果您在使用 phpseclib 时遇到问题,您可以创建日志文件并将其发布在官方支持论坛上,并在那里获得一流的支持。

    【讨论】:

      猜你喜欢
      • 2014-09-18
      • 2012-04-10
      • 2015-07-25
      • 1970-01-01
      • 1970-01-01
      • 2020-07-25
      • 2011-10-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多