List a directory in a standardized format by using MLSD command (RFC-3659). If path is omitted the current directory is assumed. "facts" is a list of strings representing the type of information desired (e.g. ["type", "size", "perm"]). Return a generator object
(self, path="", facts=[])
| 569 | self.retrlines(cmd, func) |
| 570 | |
| 571 | def mlsd(self, path="", facts=[]): |
| 572 | '''List a directory in a standardized format by using MLSD |
| 573 | command (RFC-3659). If path is omitted the current directory |
| 574 | is assumed. "facts" is a list of strings representing the type |
| 575 | of information desired (e.g. ["type", "size", "perm"]). |
| 576 | |
| 577 | Return a generator object yielding a tuple of two elements |
| 578 | for every file found in path. |
| 579 | First element is the file name, the second one is a dictionary |
| 580 | including a variable number of "facts" depending on the server |
| 581 | and whether "facts" argument has been provided. |
| 582 | ''' |
| 583 | if facts: |
| 584 | self.sendcmd("OPTS MLST " + ";".join(facts) + ";") |
| 585 | if path: |
| 586 | cmd = "MLSD %s" % path |
| 587 | else: |
| 588 | cmd = "MLSD" |
| 589 | lines = [] |
| 590 | self.retrlines(cmd, lines.append) |
| 591 | for line in lines: |
| 592 | facts_found, _, name = line.rstrip(CRLF).partition(' ') |
| 593 | entry = {} |
| 594 | for fact in facts_found[:-1].split(";"): |
| 595 | key, _, value = fact.partition("=") |
| 596 | entry[key.lower()] = value |
| 597 | yield (name, entry) |
| 598 | |
| 599 | def rename(self, fromname, toname): |
| 600 | '''Rename a file.''' |