php / pecl-networking-ssh2

Bindings for the libssh2 library
http://pecl.php.net/package/ssh2
Other
51 stars 59 forks source link

ssh2_scp_send() truncates files, incomplete file saved on remote server #69

Open triatic opened 1 year ago

triatic commented 1 year ago

Description

The following code:

<?php
$ssh2 = ssh2_connect('example.com');
ssh2_auth_pubkey_file($ssh2, 'ubuntu', 'pubkey', 'privkey');
$sftp = ssh2_sftp($ssh2);
ssh2_sftp_unlink($sftp, 'myfile');
ssh2_scp_send($ssh2, 'myfile', 'myfile');
$myfile = ssh2_sftp_stat($sftp, 'myfile');
if ($myfile['size'] != filesize('myfile')) echo 'File size mismatch, local: ' . filesize('myfile') . ', remote: ' . $myfile['size'] . "\n";

Resulted in this output:

File size mismatch, local: 3938770, remote: 2310144

But I expected this output instead:

I should get no output as the file sizes on the local and remote servers should match. ssh2_scp_send() is not sending the whole file to the remote server.

PHP Version

PHP 8.1.2

Operating System

No response