Warning: ssh2_scp_send(): Failure creating remote file: Invalid ACK response from remote in

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);
}

参看:php-sftp-seg-fault 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值