diff --git a/phpseclib/Net/SFTP.php b/phpseclib/Net/SFTP.php index 771535c3..d87ee7d8 100644 --- a/phpseclib/Net/SFTP.php +++ b/phpseclib/Net/SFTP.php @@ -2490,12 +2490,31 @@ class SFTP extends SSH2 return $this->get_stat_cache_prop($path, 'gid'); } + /** + * Recursively go through rawlist() output to get the total filesize + */ + private static function recursiveFilesize(array $files): int + { + $size = 0; + foreach ($files as $name => $file) { + if ($name == '.' || $name == '..') { + continue; + } + $size += is_array($file) ? + self::recursiveFilesize($file) : + $file->size; + } + return $size; + } + /** * Gets file size */ - public function filesize(string $path) + public function filesize(string $path, bool $recursive = false) { - return $this->get_stat_cache_prop($path, 'size'); + return !$recursive || $this->filetype($path) != 'dir' ? + $this->get_stat_cache_prop($path, 'size') : + $this->recursiveFilesize($this->rawlist($path, true)); } /** diff --git a/tests/Unit/Crypt/RSA/ModeTest.php b/tests/Unit/Crypt/RSA/ModeTest.php index fb3bc882..51b76903 100644 --- a/tests/Unit/Crypt/RSA/ModeTest.php +++ b/tests/Unit/Crypt/RSA/ModeTest.php @@ -257,7 +257,7 @@ zUlir0ACPypC1Q== $this->assertSame($data, $decrypted); } - public function testSettingOnePadding() + public function testSettingOnePadding(): void { $pub = <<