summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--paramiko/sftp_server.py4
-rw-r--r--paramiko/sftp_si.py12
-rw-r--r--tests/stub_sftp.py14
3 files changed, 29 insertions, 1 deletions
diff --git a/paramiko/sftp_server.py b/paramiko/sftp_server.py
index ce287e8f..5d161b74 100644
--- a/paramiko/sftp_server.py
+++ b/paramiko/sftp_server.py
@@ -439,6 +439,10 @@ class SFTPServer (BaseSFTP, SubsystemHandler):
tag = msg.get_text()
if tag == 'check-file':
self._check_file(request_number, msg)
+ elif tag == 'posix-rename@openssh.com':
+ oldpath = msg.get_text()
+ newpath = msg.get_text()
+ self._send_status(request_number, self.server.posix_rename(oldpath, newpath))
else:
self._send_status(request_number, SFTP_OP_UNSUPPORTED)
else:
diff --git a/paramiko/sftp_si.py b/paramiko/sftp_si.py
index 61db956c..e899108d 100644
--- a/paramiko/sftp_si.py
+++ b/paramiko/sftp_si.py
@@ -201,6 +201,18 @@ class SFTPServerInterface (object):
"""
return SFTP_OP_UNSUPPORTED
+ def posix_rename(self, oldpath, newpath):
+ """
+ Rename (or move) a file, following posix conventions. If newpath
+ already exists, it will be overwritten.
+
+ :param str oldpath:
+ the requested path (relative or absolute) of the existing file.
+ :param str newpath: the requested new path of the file.
+ :return: an SFTP error code `int` like `.SFTP_OK`.
+ """
+ return SFTP_OP_UNSUPPORTED
+
def mkdir(self, path, attr):
"""
Create a new directory with the given attributes. The ``attr``
diff --git a/tests/stub_sftp.py b/tests/stub_sftp.py
index 24380ba1..a894c2ba 100644
--- a/tests/stub_sftp.py
+++ b/tests/stub_sftp.py
@@ -23,7 +23,7 @@ A stub SFTP server for loopback SFTP testing.
import os
import sys
from paramiko import ServerInterface, SFTPServerInterface, SFTPServer, SFTPAttributes, \
- SFTPHandle, SFTP_OK, AUTH_SUCCESSFUL, OPEN_SUCCEEDED
+ SFTPHandle, SFTP_OK, SFTP_FAILURE, AUTH_SUCCESSFUL, OPEN_SUCCEEDED
from paramiko.common import o666
@@ -139,12 +139,24 @@ class StubSFTPServer (SFTPServerInterface):
def rename(self, oldpath, newpath):
oldpath = self._realpath(oldpath)
newpath = self._realpath(newpath)
+ if os.path.exists(newpath):
+ return SFTP_FAILURE
try:
os.rename(oldpath, newpath)
except OSError as e:
return SFTPServer.convert_errno(e.errno)
return SFTP_OK
+ def posix_rename(self, oldpath, newpath):
+ oldpath = self._realpath(oldpath)
+ newpath = self._realpath(newpath)
+ try:
+ os.rename(oldpath, newpath)
+ except OSError as e:
+ return SFTPServer.convert_errno(e.errno)
+ return SFTP_OK
+
+
def mkdir(self, path, attr):
path = self._realpath(path)
try: