diff --git a/phpseclib/Net/SFTP.php b/phpseclib/Net/SFTP.php index 04ad79c4..a2222929 100644 --- a/phpseclib/Net/SFTP.php +++ b/phpseclib/Net/SFTP.php @@ -1867,8 +1867,6 @@ class SFTP extends SSH2 return false; } - $this->remove_from_stat_cache($remote_file); - $flags = NET_SFTP_OPEN_WRITE | NET_SFTP_OPEN_CREATE; // according to the SFTP specs, NET_SFTP_OPEN_APPEND should "force all writes to append data at the end of the file." // in practice, it doesn't seem to do that. @@ -1885,6 +1883,8 @@ class SFTP extends SSH2 $flags|= NET_SFTP_OPEN_TRUNCATE; } + $this->remove_from_stat_cache($remote_file); + $packet = Strings::packSSH2('sNN', $remote_file, $flags, 0); if (!$this->send_sftp_packet(NET_SFTP_OPEN, $packet)) { return false; diff --git a/tests/Functional/Net/SFTPStreamTest.php b/tests/Functional/Net/SFTPStreamTest.php index 5388269a..97dce6f7 100644 --- a/tests/Functional/Net/SFTPStreamTest.php +++ b/tests/Functional/Net/SFTPStreamTest.php @@ -55,6 +55,20 @@ class Functional_Net_SFTPStreamTest extends Functional_Net_SFTPTestCase $this->assertEquals(['.', '..'], array_slice($dirs, 0, 2)); } + /** + * @group github1552 + */ + public function testStreamSelect() + { + $context = stream_context_create([ + 'sftp' => ['session' => $this->sftp], + ]); + $fp = fopen($this->buildUrl('fooo.txt'), 'wb', false, $context); + $read = [$fp]; + $write = $except = null; + stream_select($read, $write, $except, 0); + } + protected function buildUrl($suffix) { return sprintf( diff --git a/tests/Functional/Net/SFTPUserStoryTest.php b/tests/Functional/Net/SFTPUserStoryTest.php index 619e9a96..4485cef7 100644 --- a/tests/Functional/Net/SFTPUserStoryTest.php +++ b/tests/Functional/Net/SFTPUserStoryTest.php @@ -167,6 +167,23 @@ class Functional_Net_SFTPUserStoryTest extends PhpseclibFunctionalTestCase 'Failed asserting that get() returns expected example data.' ); + $this->assertTrue( + $sftp->put('file1.txt', 'xxx', SFTP::RESUME), + 'Failed asserting that an upload could be successfully resumed' + ); + + $this->assertSame( + self::$exampleDataLength + 3, + $sftp->filesize('file1.txt'), + 'Failed asserting that put example data has the expected length' + ); + + $this->assertSame( + self::$exampleData . 'zzz', + $sftp->get('file1.txt'), + 'Failed asserting that get() returns expected example data.' + ); + return $sftp; }