diff --git a/phpseclib/Net/SFTP.php b/phpseclib/Net/SFTP.php index 3065b722..1e61e0bb 100644 --- a/phpseclib/Net/SFTP.php +++ b/phpseclib/Net/SFTP.php @@ -3590,14 +3590,6 @@ class SFTP extends SSH2 if (!$this->precheck()) { return false; } - $testA = $this->version >= 5; - $testB = isset($this->extensions['posix-rename@openssh.com']) && $this->extensions['posix-rename@openssh.com'] === '1'; - if (!$testA && !$testB) { - throw new \RuntimeException( - "Extension 'posix-rename@openssh.com' is not supported by the server. " . - "Call getSupportedVersions() to see a list of supported extension" - ); - } $oldname = $this->realpath($oldname); $newname = $this->realpath($newname); @@ -3608,9 +3600,14 @@ class SFTP extends SSH2 if ($this->version >= 5) { $packet = Strings::packSSH2('ssN', $oldname, $newname, 2); // 2 = SSH_FXP_RENAME_ATOMIC $this->send_sftp_packet(NET_SFTP_RENAME, $packet); - } else { + } elseif (isset($this->extensions['posix-rename@openssh.com']) && $this->extensions['posix-rename@openssh.com'] === '1') { $packet = Strings::packSSH2('sss', 'posix-rename@openssh.com', $oldname, $newname); $this->send_sftp_packet(NET_SFTP_EXTENDED, $packet); + } else { + throw new \RuntimeException( + "Extension 'posix-rename@openssh.com' is not supported by the server. " . + "Call getSupportedVersions() to see a list of supported extension" + ); } $response = $this->get_sftp_packet();