diff --git a/phpseclib/Net/SFTP.php b/phpseclib/Net/SFTP.php index 2145f7bb..7df5e8c5 100644 --- a/phpseclib/Net/SFTP.php +++ b/phpseclib/Net/SFTP.php @@ -1635,7 +1635,7 @@ class SFTP extends SSH2 public function chgrp($filename, $gid, $recursive = false) { $attr = $this->version < 4 ? - pack('N3', NET_SFTP_ATTR_UIDGID, $gid, -1) : + pack('N3', NET_SFTP_ATTR_UIDGID, -1, $gid) : Strings::packSSH2('Nss', NET_SFTP_ATTR_OWNERGROUP, '', $gid); return $this->setstat($filename, $attr, $recursive); diff --git a/tests/Functional/Net/SFTPUserStoryTest.php b/tests/Functional/Net/SFTPUserStoryTest.php index 24481715..56b2809a 100644 --- a/tests/Functional/Net/SFTPUserStoryTest.php +++ b/tests/Functional/Net/SFTPUserStoryTest.php @@ -765,5 +765,22 @@ class Functional_Net_SFTPUserStoryTest extends PhpseclibFunctionalTestCase $list_cache_disabled = $sftp->rawlist('.', true); $this->assertEquals($list_cache_enabled, $list_cache_disabled, 'The files should be the same regardless of stat cache', 0.0, 10, true); + + return $sftp; + } + + /** + * @depends testRawlistDisabledStatCache + */ + public function testChownChgrp($sftp) + { + $stat = $sftp->stat(self::$scratchDir); + $this->assertTrue($sftp->chown(self::$scratchDir, $stat['uid'])); + $this->assertTrue($sftp->chgrp(self::$scratchDir, $stat['gid'])); + + $sftp->clearStatCache(); + $stat2 = $sftp->stat(self::$scratchDir); + $this->assertSame($stat['uid'], $stat2['uid']); + $this->assertSame($stat['gid'], $stat2['gid']); } }