diff options
author | Robey Pointer <robey@lag.net> | 2005-01-09 05:27:07 +0000 |
---|---|---|
committer | Robey Pointer <robey@lag.net> | 2005-01-09 05:27:07 +0000 |
commit | 1eda9b051bd59e3b7a22a3ef44b55fc7b1b35a6c (patch) | |
tree | 3f4a096198a1d6cf73fc89f7e58c14c57ae4625e | |
parent | 811f2bf30f011f911fa72b29e7a566e6f6c2acab (diff) |
[project @ Arch-1:robey@lag.net--2003-public%secsh--dev--1.0--patch-137]
added listdir_attr()
add SFTPClient.listdir_attr() to fetch a list of files & their attributes,
instead of just their filenames. artur piwko would find this useful.
-rw-r--r-- | paramiko/sftp_attr.py | 4 | ||||
-rw-r--r-- | paramiko/sftp_client.py | 27 |
2 files changed, 25 insertions, 6 deletions
diff --git a/paramiko/sftp_attr.py b/paramiko/sftp_attr.py index 90bf8d7e..5fb45d0f 100644 --- a/paramiko/sftp_attr.py +++ b/paramiko/sftp_attr.py @@ -82,9 +82,11 @@ class SFTPAttributes (object): ### internals... - def _from_msg(cls, msg): + def _from_msg(cls, msg, filename=None): attr = cls() attr._unpack(msg) + if filename is not None: + attr.filename = filename return attr _from_msg = classmethod(_from_msg) diff --git a/paramiko/sftp_client.py b/paramiko/sftp_client.py index 6ddd1572..f4753ce9 100644 --- a/paramiko/sftp_client.py +++ b/paramiko/sftp_client.py @@ -76,11 +76,29 @@ class SFTPClient (BaseSFTP): Return a list containing the names of the entries in the given C{path}. The list is in arbitrary order. It does not include the special entries C{'.'} and C{'..'} even if they are present in the folder. + This method is meant to mirror C{os.listdir} as closely as possible. + For a list of full L{SFTPAttributes} objects, see L{listdir_attr}. @param path: path to list. - @type path: string + @type path: str @return: list of filenames. - @rtype: list of string + @rtype: list of str + """ + return [f.filename for f in self.listdir_attr(path)] + + def listdir_attr(self, path): + """ + Return a list containing L{SFTPAttributes} objects corresponding to + files in the given C{path}. The list is in arbitrary order. It does + not include the special entries C{'.'} and C{'..'} even if they are + present in the folder. + + @param path: path to list. + @type path: str + @return: list of attributes. + @rtype: list of L{SFTPAttributes} + + @since: 1.2 """ t, msg = self._request(CMD_OPENDIR, path) if t != CMD_HANDLE: @@ -99,10 +117,9 @@ class SFTPClient (BaseSFTP): for i in range(count): filename = msg.get_string() longname = msg.get_string() - attr = SFTPAttributes._from_msg(msg) + attr = SFTPAttributes._from_msg(msg, filename) if (filename != '.') and (filename != '..'): - filelist.append(filename) - # currently we ignore the rest + filelist.append(attr) self._request(CMD_CLOSE, handle) return filelist |