diff --git a/phpseclib/Net/SFTP.php b/phpseclib/Net/SFTP.php index e139be53..1013b4e8 100644 --- a/phpseclib/Net/SFTP.php +++ b/phpseclib/Net/SFTP.php @@ -1876,10 +1876,7 @@ class SFTP extends SSH2 if ($local_start >= 0) { fseek($fp, $local_start); - } elseif ($mode & self::RESUME_START) { - // do nothing - } else { - fseek($fp, $offset); + $size-= $local_start; } } elseif ($dataCallback) { $size = 0; diff --git a/tests/Functional/Net/SFTPUserStoryTest.php b/tests/Functional/Net/SFTPUserStoryTest.php index 6539c675..fcc41eda 100644 --- a/tests/Functional/Net/SFTPUserStoryTest.php +++ b/tests/Functional/Net/SFTPUserStoryTest.php @@ -651,5 +651,28 @@ class Functional_Net_SFTPUserStoryTest extends PhpseclibFunctionalTestCase $this->assertSame($stat['type'], NET_SFTP_TYPE_SYMLINK); $sftp->enableStatCache(); + + return $sftp; + } + + /** + * @depends testStatVsLstat + * @group github830 + */ + public function testUploadOffsets($sftp) + { + $sftp->put('offset.txt', 'res.txt', SFTP::SOURCE_LOCAL_FILE, 0, 10); + $this->assertSame( + substr(self::$exampleData, 10), + $sftp->get('offset.txt'), + 'Failed asserting that portions of a file could be uploaded.' + ); + + $sftp->put('offset.txt', 'res.txt', SFTP::SOURCE_LOCAL_FILE, self::$exampleDataLength - 100); + $this->assertSame( + substr(self::$exampleData, 10, -90) . self::$exampleData, + $sftp->get('offset.txt'), + 'Failed asserting that you could upload into the middle of a file.' + ); } }