Merge branch '3.0'

This commit is contained in:
terrafrost 2024-09-15 13:36:12 -05:00
commit b82a58ae46

View File

@ -3245,7 +3245,9 @@ class SFTP extends SSH2
return false;
}
if (!isset($this->extensions['posix-rename@openssh.com']) || $this->extensions['posix-rename@openssh.com'] !== '1') {
$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"
@ -3258,8 +3260,13 @@ class SFTP extends SSH2
return false;
}
$packet = Strings::packSSH2('sss', 'posix-rename@openssh.com', $oldname, $newname);
$this->send_sftp_packet(PacketType::EXTENDED, $packet);
if ($this->version >= 5) {
$packet = Strings::packSSH2('ssN', $oldname, $newname, 2); // 2 = SSH_FXP_RENAME_ATOMIC
$this->send_sftp_packet(PacketType::RENAME, $packet);
} else {
$packet = Strings::packSSH2('sss', 'posix-rename@openssh.com', $oldname, $newname);
$this->send_sftp_packet(PacketType::EXTENDED, $packet);
}
$response = $this->get_sftp_packet();
if ($this->packet_type != PacketType::STATUS) {