Retrieve data in line mode. A new port is created for you. Args: cmd: A RETR, LIST, or NLST command. callback: An optional single parameter callable that is called for each line with the trailing CRLF stripped. [default: print_lin
(self, cmd, callback = None)
| 442 | return self.voidresp() |
| 443 | |
| 444 | def retrlines(self, cmd, callback = None): |
| 445 | """Retrieve data in line mode. A new port is created for you. |
| 446 | |
| 447 | Args: |
| 448 | cmd: A RETR, LIST, or NLST command. |
| 449 | callback: An optional single parameter callable that is called |
| 450 | for each line with the trailing CRLF stripped. |
| 451 | [default: print_line()] |
| 452 | |
| 453 | Returns: |
| 454 | The response code. |
| 455 | """ |
| 456 | if callback is None: |
| 457 | callback = print_line |
| 458 | self.sendcmd('TYPE A') |
| 459 | with self.transfercmd(cmd) as conn, \ |
| 460 | conn.makefile('r', encoding=self.encoding) as fp: |
| 461 | while 1: |
| 462 | line = fp.readline(self.maxline + 1) |
| 463 | if len(line) > self.maxline: |
| 464 | raise Error("got more than %d bytes" % self.maxline) |
| 465 | if self.debugging > 2: |
| 466 | print('*retr*', repr(line)) |
| 467 | if not line: |
| 468 | break |
| 469 | if line[-2:] == CRLF: |
| 470 | line = line[:-2] |
| 471 | elif line[-1:] == '\n': |
| 472 | line = line[:-1] |
| 473 | callback(line) |
| 474 | # shutdown ssl layer |
| 475 | if _SSLSocket is not None and isinstance(conn, _SSLSocket): |
| 476 | conn.unwrap() |
| 477 | return self.voidresp() |
| 478 | |
| 479 | def storbinary(self, cmd, fp, blocksize=8192, callback=None, rest=None): |
| 480 | """Store a file in binary mode. A new port is created for you. |