mirror of
https://github.com/phpseclib/phpseclib.git
synced 2024-12-25 11:20:03 +00:00
SFTP: refactor posix_rename() somewhat
This commit is contained in:
parent
89f2385a6a
commit
c8da4c50d5
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user