简体   繁体   中英

Why my tar.gz file was truncated in the process of transfer by ssh2_scp_send function?

There is a file in my local pc.

ls -al /tmp/back.tar.gz
-rw-r--r-- 1 root root 11219553 Nov 29 23:13 /tmp/back.tar.gz

Let's upload the back.tar.gz with ssh2_scp_send into my remote vps.

<?php
    $vps_ip= 'xxxx';
    $port = 'yyyy';
    $user = 'root';
    $passwd = 'zzzz';
    $connection = ssh2_connect($vps_ip, $port);
    ssh2_auth_password($connection,$user,$passwd);
    ssh2_scp_send($connection,'/tmp/back.tar.gz','/home/back.tar.gz');
?>

Login into ssh with ssh -p yyyy root@xxxx to execute ls command in my vps.

ls  -al  /home/back.tar.gz
-rw-r--r-- 1 root root 11206656 Nov 29 10:10 /home/back.tar.gz

Where is the 12897 bytes left?

Now i upload the file /tmp/back.tar.gz in my local pc into remote vps the second time,when the php program executed.
Login into ssh with ssh -p yyyy root@xxxx to execute ls command in my vps.

ls  -al  /home/back.tar.gz
-rw-r--r-- 1 root root 11219505 Nov 29 10:10 /home/back.tar.gz

I think that there is a bug in ssh2_scp_send function ,it is unstable. I have tested also with scp command for three times:

scp -P  $port root@$vps_ip:/home/back.tar.gz    /tmp

Login into ssh with ssh -p yyyy root@xxxx to execute ls command in my vps.

ls  -al  /home/back.tar.gz
-rw-r--r-- 1 root root 11219553 Nov 29 10:10 /home/back.tar.gz

It is my conclusion that some bug in ssh2_scp_send function.

Buffer works here.

ssh2_exec($connection, 'exit');

To write bytes in buffer before closing the connection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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