ssh2_scp_send第一次没问题,但第二次失败了

I am making use of php ssh2_scp_send to transfer files to the remote machine, but it is a bit weird, it works for the first time but fails my second call with the following error

//success for file transfer
if (!(ssh2_scp_send($this->conn, $lpath, $rpath, 0777))){
            throw new Exception("File transfer failed!");
        }
        ssh2_exec($this->conn, 'exit'); 

//fail this time
if (!(ssh2_scp_send($this->conn, $lpath, $rpath, 0777))){
            throw new Exception("File transfer failed!");
        }
        ssh2_exec($this->conn, 'exit')

"Warning: ssh2_scp_send(): Failed copying file in /var/www/trunk/rsetting/class/ssh.class.php on line 57"

Any help will be appreciated~Thanks

doxqszx09742
doxqszx09742 是的,完全相同的错误
6 年多之前 回复
doulezhi5326
doulezhi5326 是同样的错误吗?
6 年多之前 回复
duanqiao1949
duanqiao1949 感谢您的评论,我删除了该代码,但问题仍然在这里:(
6 年多之前 回复
doubianyan9749
doubianyan9749 因为您在第一次转移后关闭了连接..ssh2_exec($this->conn,'exit');
6 年多之前 回复

2个回答



将php-ssh2扩展名更新为0.13就可以了。</ p>
</ div>

展开原文

原文

update php-ssh2 extension to 0.13 will be fine.



我有同样的问题但通过调用此函数解决了它:</ p>

ssh2_exec ($ conn,'exit'); </ code> </ p>

在循环结束时。
我认为此命令刷新缓冲区并正确写入最后一个远程文件。</ p >
</ div>

展开原文

原文

I had the same problem but solved it by calling this function:

ssh2_exec($conn, 'exit');

at the end of the loop. I think this command flush the buffer and write correctly the last remote file.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问