ssh2.sftp问题
想在通过php和ssh在远程服务器把一个文件拷贝到本地,之前scp_recv不行,后来用了ssh2_scp也不行,请大神帮看一下,代码如下:if (isset($_POST['download'])) {# code...
$ip = $_POST['ip'];
$filename=$ip.".tar.gz ";
$cmd = "tar zcvf ".$filename.$_POST['path'];
$remote_file="/home/test/$filename";
$local_file="/tmp/$filename";
$conn=ssh2_connect($ip,22,array('hostkey' => 'ssh-rsa' ));
ssh2_auth_pubkey_file($conn, 'test', 'test.pub', 'test');
$sftp = ssh2_sftp($conn);
$stream = @fopen("ssh2.sftp://$sftp$remote_file",'r');
@fclose($stream);
$data = file_get_contents("ssh2.sftp://$sftp$remote_file");
file_put_contents($local_file, $data);
}apache日志报错如下:
PHP Warning:file_get_contents(ssh2.sftp://Resource id #3/home/getlog/test.tar.gz ) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: operation failed in
页:
[1]