summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRobey Pointer <robey@lag.net>2004-09-11 20:50:39 +0000
committerRobey Pointer <robey@lag.net>2004-09-11 20:50:39 +0000
commit3a4ca74e0a16d07296fc51391d466819b2ca3dad (patch)
tree86a1ca9ce9808b9cf57cb3675201dbaa54d83e5c
parent5176b1ab85703e8f6faaa15f4c4809634fd47cb0 (diff)
[project @ Arch-1:robey@lag.net--2003-public%secsh--dev--1.0--patch-84]
add sftp.normalize kevin c. dorff pointed out that it would be nice to expose a way to determine the server's "current working directory", so this new method (normalize) directly maps to REALPATH.
-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...