Store a file in binary mode. A new port is created for you. Args: cmd: A STOR command. fp: A file-like object with a read(num_bytes) method. blocksize: The maximum data size to read from fp and send over the connection at once. [default:
(self, cmd, fp, blocksize=8192, callback=None, rest=None)
| 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. |
| 481 | |
| 482 | Args: |
| 483 | cmd: A STOR command. |
| 484 | fp: A file-like object with a read(num_bytes) method. |
| 485 | blocksize: The maximum data size to read from fp and send over |
| 486 | the connection at once. [default: 8192] |
| 487 | callback: An optional single parameter callable that is called on |
| 488 | each block of data after it is sent. [default: None] |
| 489 | rest: Passed to transfercmd(). [default: None] |
| 490 | |
| 491 | Returns: |
| 492 | The response code. |
| 493 | """ |
| 494 | self.voidcmd('TYPE I') |
| 495 | with self.transfercmd(cmd, rest) as conn: |
| 496 | while buf := fp.read(blocksize): |
| 497 | conn.sendall(buf) |
| 498 | if callback: |
| 499 | callback(buf) |
| 500 | # shutdown ssl layer |
| 501 | if _SSLSocket is not None and isinstance(conn, _SSLSocket): |
| 502 | conn.unwrap() |
| 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. |