开发者

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. 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). The sender and the receiver server use both CentOS 5.5, and are virtual servers on a VmWare Vsphere hyperv开发者_运维知识库isor. 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.

How can I understand why the transfert hang? The sshd logs on destination server just show connection and deconnection.

Thanks


On windows ssh_scp seems to keep the connection open and hang there with file in buffer.

Try making an explicit call to "exit" to close the session (flushing file content to disk):

<?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. I read and fwrite() data by block of 512kb. 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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜