From 6c8affcf11a8cfb256c98e53933a6298b33a5d13 Mon Sep 17 00:00:00 2001 From: Mathieu Pipet Date: Thu, 2 Jun 2016 16:22:34 +0200 Subject: [PATCH] fixed sending stream resulting in a zero byte file --- phpseclib/Net/SFTP.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/phpseclib/Net/SFTP.php b/phpseclib/Net/SFTP.php index 4840f269..2a91f661 100644 --- a/phpseclib/Net/SFTP.php +++ b/phpseclib/Net/SFTP.php @@ -1933,7 +1933,7 @@ class Net_SFTP extends Net_SSH2 // make the SFTP packet be exactly 4096 bytes by including the bytes in the NET_SFTP_WRITE packets "header" $sftp_packet_size-= strlen($handle) + 25; $i = 0; - while ($dataCallback || ($sent < $size)) { + while ($dataCallback || ($size === 0 || $sent < $size)) { if ($dataCallback) { $temp = call_user_func($dataCallback, $sftp_packet_size); if (is_null($temp)) { @@ -1941,7 +1941,11 @@ class Net_SFTP extends Net_SSH2 } } else { $temp = isset($fp) ? fread($fp, $sftp_packet_size) : substr($data, $sent, $sftp_packet_size); + if ($temp === false) { + break; + } } + $subtemp = $offset + $sent; $packet = pack('Na*N3a*', strlen($handle), $handle, $subtemp / 4294967296, $subtemp, strlen($temp), $temp); if (!$this->_send_sftp_packet(NET_SFTP_WRITE, $packet)) {