开发者

php ssh2 fgets();

im try to open a file on a remote host and read it, but i got a return value of 1. Maybe anyone find my bug.

public function get()

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

$this->connection is:

开发者_JAVA百科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;
}

Connection works also, can send other commands like tar ...


Might I recommend phpseclib, a pure PHP SFTP implementation? It's easier to use and much better supported. Here's how you'd do it with that:

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

If you have problems with phpseclib you can create log files and post them on the official support forums and get top notch support there.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜