简体   繁体   English

ssh2_scp_send() 无法在一台服务器上传输整个文件

[英]ssh2_scp_send() fail to transfert the whole file on one server

i use ssh2_scp_send() function to send files from a server to another one via ssh way.我使用 ssh2_scp_send() function 通过 ssh 方式将文件从服务器发送到另一个服务器。 The test script and the real application run just fine on my Ubuntu workstation, between it and a distant server, and between my Windows PC and a development CentOS 5.0 Linux server at my office. The test script and the real application run just fine on my Ubuntu workstation, between it and a distant server, and between my Windows PC and a development CentOS 5.0 Linux server at my office. In my customer place, the ssh2_scp_send() stop, return false, and the sent file is truncated (2MB for a 6.5MB).在我的客户处,ssh2_scp_send() 停止,返回 false,并且发送的文件被截断(6.5MB 为 2MB)。 The sender and the receiver server use both CentOS 5.5, and are virtual servers on a VmWare Vsphere hypervisor.发送方和接收方服务器都使用 CentOS 5.5,并且是 VmWare Vsphere 管理程序上的虚拟服务器。 There is a virtual local network between the two.两者之间有一个虚拟局域网。 Smaller files are not truncated.较小的文件不会被截断。 There is plenty of disk space on each server.每台服务器上都有足够的磁盘空间。

Here is the test script:这是测试脚本:

<?php

$source = '/sourcefile.dat';
$dest = '/destfile.dat';

$serveur = 'sshserver';
$login = 'login';
$sPub = 'public_key';
$sPriv = 'private_key';
$passphrase = 'pass';

$aSSHMethods = array(
        'kex' => 'diffie-hellman-group1-sha1',
        'client_to_server' => array(
                'crypt' => '3des-cbc,aes256-cbc,aes192-cbc,aes128-cbc',
                'comp' => 'none'),
        'server_to_client' => array(
                'crypt' => '3des-cbc,aes256-cbc,aes192-cbc,aes128-cbc',
                'comp' => 'none'),
        );

$rSSH = ssh2_connect($serveur, 22, $aSSHMethods);   
ssh2_auth_pubkey_file($rSSH, $login, $sPub, $sPriv, $passphrase);
ssh2_scp_send($rSSH, $source, $dest);

I tried to replace ssh2_scp_send() by a ssh2_sftp/fopen/fwrite/fclose, but it run the same way, and is slower.我试图用 ssh2_sftp/fopen/fwrite/fclose 替换 ssh2_scp_send(),但它的运行方式相同,而且速度较慢。

How can I understand why the transfert hang?我怎样才能理解传输挂起的原因? The sshd logs on destination server just show connection and deconnection.目标服务器上的 sshd 日志仅显示连接和断开连接。

Thanks谢谢

On windows ssh_scp seems to keep the connection open and hang there with file in buffer.在 windows 上,ssh_scp 似乎保持连接打开并挂在那里,文件在缓冲区。

Try making an explicit call to "exit" to close the session (flushing file content to disk):尝试显式调用“exit”以关闭 session(将文件内容刷新到磁盘):

<?php 
  $objConnection = ssh2_connect($strHost, $strPort, $methods, $callbacks); 
  ssh2_auth_password($objConnection, $strUser, $strPassword); 
  ssh2_scp_send($objConnection , $strSource, $strDest); 

  // Add this to flush buffers/close session 
  ssh2_exec($objConnection, 'exit'); 

Not sure if this will solve your issue, but it may be worth a try.不确定这是否会解决您的问题,但可能值得一试。

In fact, my customer tells me this morning the ssh2_sftp/fopen/fwrite/fclose solution run better than the ssh2_scp_send() one.事实上,我的客户今天早上告诉我 ssh2_sftp/fopen/fwrite/fclose 解决方案比 ssh2_scp_send() 解决方案运行得更好。 I read and fwrite() data by block of 512kb.我按 512kb 的块读取和 fwrite() 数据。 His first answer was inaccurate.他的第一个答案是不准确的。 But I still dont understand why ssh2_scp_send() run on severals boxes and not on others one (maybe stefgosselin has part of the answer).但我仍然不明白为什么 ssh2_scp_send() 在几个盒子上运行而不是在其他盒子上运行(也许 stefgosselin 有部分答案)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM