From 320c43a4a0ff8838dc810c61b90e7b62d3c0d060 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Mon, 28 Aug 2023 08:27:41 -0500 Subject: [PATCH] SFTP: fix issue with get() downloading to files / streams the code that's being removed has its origins in 65193d9a25baa59bc34479322a694f2cf1f16180. in that commit the packet length is set outside of the while loop. this would continue to be the case until https://github.com/phpseclib/phpseclib/pull/945. --- phpseclib/Net/SFTP.php | 8 -------- tests/Functional/Net/SFTPUserStoryTest.php | 13 +++++++++++++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/phpseclib/Net/SFTP.php b/phpseclib/Net/SFTP.php index 0bb6c7b3..0c372ef0 100644 --- a/phpseclib/Net/SFTP.php +++ b/phpseclib/Net/SFTP.php @@ -2748,14 +2748,6 @@ class Net_SFTP extends Net_SSH2 } } - if ($length > 0 && $length <= $offset - $start) { - if ($local_file === false) { - $content = substr($content, 0, $length); - } else { - ftruncate($fp, $length + $res_offset); - } - } - if ($fclose_check) { fclose($fp); diff --git a/tests/Functional/Net/SFTPUserStoryTest.php b/tests/Functional/Net/SFTPUserStoryTest.php index 5d7590fe..1e32bcbd 100644 --- a/tests/Functional/Net/SFTPUserStoryTest.php +++ b/tests/Functional/Net/SFTPUserStoryTest.php @@ -777,5 +777,18 @@ class Functional_Net_SFTPUserStoryTest extends PhpseclibFunctionalTestCase $stat2 = $sftp->stat(self::$scratchDir); $this->assertSame($stat['uid'], $stat2['uid']); $this->assertSame($stat['gid'], $stat2['gid']); + + return $sftp; + } + + /** + * @depends testChownChgrp + * @group github1934 + */ + public function testCallableGetWithLength($sftp) + { + $sftp->put('test.txt', 'zzzzz'); + $sftp->get('test.txt', function($data) {}, 0, 1); + $this->assertTrue(true); } }