Store a file in line mode. A new port is created for you. Args: cmd: A STOR command. fp: A file-like object with a readline() method. callback: An optional single parameter callable that is called on each line after it is sent. [default: N
(self, cmd, fp, callback=None)
| 503 | return self.voidresp() |
| 504 | |
| 505 | def storlines(self, cmd, fp, callback=None): |
| 506 | """Store a file in line mode. A new port is created for you. |
| 507 | |
| 508 | Args: |
| 509 | cmd: A STOR command. |
| 510 | fp: A file-like object with a readline() method. |
| 511 | callback: An optional single parameter callable that is called on |
| 512 | each line after it is sent. [default: None] |
| 513 | |
| 514 | Returns: |
| 515 | The response code. |
| 516 | """ |
| 517 | self.voidcmd('TYPE A') |
| 518 | with self.transfercmd(cmd) as conn: |
| 519 | while 1: |
| 520 | buf = fp.readline(self.maxline + 1) |
| 521 | if len(buf) > self.maxline: |
| 522 | raise Error("got more than %d bytes" % self.maxline) |
| 523 | if not buf: |
| 524 | break |
| 525 | if buf[-2:] != B_CRLF: |
| 526 | if buf[-1] in B_CRLF: buf = buf[:-1] |
| 527 | buf = buf + B_CRLF |
| 528 | conn.sendall(buf) |
| 529 | if callback: |
| 530 | callback(buf) |
| 531 | # shutdown ssl layer |
| 532 | if _SSLSocket is not None and isinstance(conn, _SSLSocket): |
| 533 | conn.unwrap() |
| 534 | return self.voidresp() |
| 535 | |
| 536 | def acct(self, password): |
| 537 | '''Send new account name.''' |