Created
January 27, 2023 13:16
-
-
Save hashihei/4d5d229d4e39b53cc4657a34fda9edca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class myFTPS(FTP): | |
def __init__(self, host='', user='', passwd='', acct='', | |
timeout=_GLOBAL_DEFAULT_TIMEOUT, source_address=None, *, | |
encoding='utf-8'): | |
super().__init__(host='', user='', passwd='', acct='', | |
timeout=_GLOBAL_DEFAULT_TIMEOUT, source_address=None, *, | |
encoding='utf-8') | |
def storbinary(self, cmd, fp, blocksize=8192, callback=None, rest=None): | |
"""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: 8192] | |
callback: An optional single parameter callable that is called on | |
each block of data after it is sent. [default: None] | |
rest: Passed to transfercmd(). [default: None] | |
Returns: | |
The response code. | |
""" | |
self.voidcmd('TYPE I') | |
with self.transfercmd(cmd, rest) as conn: | |
while 1: | |
buf = fp.read(blocksize) | |
if not buf: | |
break | |
conn.sendall(buf) | |
if callback: | |
callback(buf) | |
# shutdown ssl layer | |
if _SSLSocket is not None and isinstance(conn, _SSLSocket): | |
pass | |
return self.voidresp() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment