- 論壇徽章:
- 0
|
想在通過(guò)php和ssh在遠(yuǎn)程服務(wù)器把一個(gè)文件拷貝到本地,之前scp_recv不行,后來(lái)用了ssh2_scp也不行,請(qǐng)大神幫看一下,代碼如下:- 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);
-
- }
復(fù)制代碼 apache日志報(bào)錯(cuò)如下:
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
|
|