From 1d1c2782e93c8bb75f05bb8000fcf8660c06a764 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Wed, 27 Feb 2013 22:10:33 -0600 Subject: [PATCH] SFTP: Fix bug whereby sometimes download amount would be ignored --- phpseclib/Net/SFTP.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/phpseclib/Net/SFTP.php b/phpseclib/Net/SFTP.php index 2614937b..eacfb674 100644 --- a/phpseclib/Net/SFTP.php +++ b/phpseclib/Net/SFTP.php @@ -1681,15 +1681,18 @@ class Net_SFTP extends Net_SSH2 { } if ($length > 0 && $length <= $offset - $size) { - if ($local_file === false) { - $content = substr($content, 0, $length); - } else { - ftruncate($fp, $length); - } break; } } + if ($length > 0 && $length <= strlen($content)) { + if ($local_file === false) { + $content = substr($content, 0, $length); + } else { + ftruncate($fp, $length); + } + } + if ($local_file !== false) { fclose($fp); }