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); }