ssh2_scp_send($this->conn, $local_file, $remote_file, 0777);
Warning: ssh2_scp_send(): Failure creating remote file: Invalid ACK response from remote in ***
可以改用 @fopen('ssh2.sftp://' . intval($sftp) . $distFilePath, 'w');
注意$sftp需要用intval一下
PHP5.6后函数ssh2_sftp返回的资源不允许了 有了ssh2_sftp的返回 必须先intval一下然后建立远程连接
// 测试示例:
<?php
$host = 'lulu-**';
$ssh2PubKey = '**.pub';
$priKey = '**/id_rsa';
$username = 'ar';
$connection = ssh2_connect($host, 22);
$loginResult = ssh2_auth_pubkey_file($connection, $username, $ssh2PubKey, $priKey);
$sourcePath = 'data/test.txt';
$distFilePath = '/inbound/test1.txt';
$sftp = ssh2_sftp($connection);
$sftpStream = @fopen('ssh2.sftp://' . intval($sftp) . $distFilePath, 'w');
try {
if (!$sftpStream) {
throw new Exception("Could not open remote file: $distFilePath");
}
$data_to_send = @file_get_contents($sourcePath);
if ($data_to_send === false) {
throw new Exception("Could not open local file: $sourcePath.");
}
if (@fwrite($sftpStream, $data_to_send) === false) {
throw new Exception("Could not send data from file: $sourcePath.");
}
fclose($sftpStream);
} catch (Exception $e) {
print_r($e->getMessage());
fclose($sftpStream);
}
版权声明:本文为p763833631原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。