summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--paramiko/sftp_client.py24
1 files changed, 22 insertions, 2 deletions
diff --git a/paramiko/sftp_client.py b/paramiko/sftp_client.py
index c72d4908..f9b8e693 100644
--- a/paramiko/sftp_client.py
+++ b/paramiko/sftp_client.py
@@ -310,9 +310,9 @@ class SFTPClient (BaseSFTP):
relative pathname.
@param path: path of the symbolic link file.
- @type path: string
+ @type path: str
@return: target path.
- @rtype: string
+ @rtype: str
"""
t, msg = self._request(CMD_READLINK, path)
if t != CMD_NAME:
@@ -324,6 +324,26 @@ class SFTPClient (BaseSFTP):
raise SFTPError('Readlink returned %d results' % count)
return msg.get_string()
+ def normalize(self, path):
+ """
+ Return the normalized path (on the server) of a given path. This
+ can be used to quickly resolve symbolic links or determine what the
+ server is considering to be the "current folder" (by passing C{'.'}
+ as C{path}).
+
+ @param path: path to be normalized.
+ @type path: str
+ @return: normalized form of the given path.
+ @rtype: str
+ """
+ t, msg = self._request(CMD_REALPATH, path)
+ if t != CMD_NAME:
+ raise SFTPError('Expected name response')
+ count = msg.get_int()
+ if count != 1:
+ raise SFTPError('Realpath returned %d results' % count)
+ return msg.get_string()
+
### internals...