pecl-networking-ssh2 icon indicating copy to clipboard operation
pecl-networking-ssh2 copied to clipboard

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

Open triatic opened this issue 2 years ago • 0 comments

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

triatic avatar May 25 '23 11:05 triatic