summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMika Pflüger <Mika Pflüger mika@mikapflueger.de>2015-01-06 20:14:34 +0100
committerMika Pflüger <Mika Pflüger mika@mikapflueger.de>2015-01-06 20:20:32 +0100
commit4d968c22b56bf045dca6abd0da891b6db9724c9f (patch)
tree571d604a026a18276779d30063bc6d142d57db7a
parent46efa38fc1ee218789593c8a26b5d70c2c22d5a3 (diff)
Add method for "posix-rename@openssh.com" extension for SFTP client.
Based on work of Warren Turkal
-rw-r--r--paramiko/sftp_client.py21
1 files changed, 19 insertions, 2 deletions
diff --git a/paramiko/sftp_client.py b/paramiko/sftp_client.py
index 89840eaa..2979544f 100644
--- a/paramiko/sftp_client.py
+++ b/paramiko/sftp_client.py
@@ -33,7 +33,7 @@ from paramiko.sftp import BaseSFTP, CMD_OPENDIR, CMD_HANDLE, SFTPError, CMD_READ
CMD_NAME, CMD_CLOSE, SFTP_FLAG_READ, SFTP_FLAG_WRITE, SFTP_FLAG_CREATE, \
SFTP_FLAG_TRUNC, SFTP_FLAG_APPEND, SFTP_FLAG_EXCL, CMD_OPEN, CMD_REMOVE, \
CMD_RENAME, CMD_MKDIR, CMD_RMDIR, CMD_STAT, CMD_ATTRS, CMD_LSTAT, \
- CMD_SYMLINK, CMD_SETSTAT, CMD_READLINK, CMD_REALPATH, CMD_STATUS, SFTP_OK, \
+ CMD_SYMLINK, CMD_SETSTAT, CMD_READLINK, CMD_REALPATH, CMD_STATUS, CMD_EXTENDED, SFTP_OK, \
SFTP_EOF, SFTP_NO_SUCH_FILE, SFTP_PERMISSION_DENIED
from paramiko.sftp_attr import SFTPAttributes
@@ -354,7 +354,7 @@ class SFTPClient(BaseSFTP, ClosingContextManager):
Rename a file or folder from ``oldpath`` to ``newpath``.
:param str oldpath: existing name of the file or folder
- :param str newpath: new name for the file or folder
+ :param str newpath: new name for the file or folder, must not exist already
:raises IOError: if ``newpath`` is a folder, or something else goes
wrong
@@ -364,6 +364,23 @@ class SFTPClient(BaseSFTP, ClosingContextManager):
self._log(DEBUG, 'rename(%r, %r)' % (oldpath, newpath))
self._request(CMD_RENAME, oldpath, newpath)
+ def posix_rename(self, oldpath, newpath):
+ """
+ Rename a file or folder from ``oldpath`` to ``newpath``, following
+ posix conventions.
+
+ :param str oldpath: existing name of the file or folder
+ :param str newpath: new name for the file or folder, will be
+ overwritten if it already exists
+
+ :raises IOError: if ``newpath`` is a folder, posix-rename is not
+ supported by the server or something else goes wrong
+ """
+ oldpath = self._adjust_cwd(oldpath)
+ newpath = self._adjust_cwd(newpath)
+ self._log(DEBUG, 'posix_rename(%r, %r)' % (oldpath, newpath))
+ self._request(CMD_EXTENDED, "posix-rename@openssh.com", oldpath, newpath)
+
def mkdir(self, path, mode=o777):
"""
Create a folder (directory) named ``path`` with numeric mode ``mode``.