Update ftplib to CPython 3.11.5 by dvermd · Pull Request #5073 · RustPython/RustPython
# The class itself class FTP:
'''An FTP client class.
To create a connection, call the class using these arguments: host, user, passwd, acct, timeout host, user, passwd, acct, timeout, source_address, encoding
The first four arguments are all strings, and have default value ''. timeout must be numeric and defaults to None if not passed, meaning that no timeout will be set on any ftp socket(s) The parameter ´timeout´ must be numeric and defaults to None if not passed, meaning that no timeout will be set on any ftp socket(s). If a timeout is passed, then this is now the default timeout for all ftp socket operations for this instance. The last parameter is the encoding of filenames, which defaults to utf-8.
Then use self.connect() with optional host and port argument.
# Initialization method (called by class instantiation). # Initialize host to localhost, port to standard ftp port # Optional arguments are host (for connect()), # and user, passwd, acct (for login()) def __init__(self, host='', user='', passwd='', acct='', timeout=_GLOBAL_DEFAULT_TIMEOUT, source_address=None): timeout=_GLOBAL_DEFAULT_TIMEOUT, source_address=None, *, encoding='utf-8'): """Initialization method (called by class instantiation). Initialize host to localhost, port to standard ftp port. Optional arguments are host (for connect()), and user, passwd, acct (for login()). """ self.encoding = encoding self.source_address = source_address self.timeout = timeout if host:
def makepasv(self): """Internal: Does the PASV or EPSV handshake -> (address, port)""" if self.af == socket.AF_INET: host, port = parse227(self.sendcmd('PASV')) untrusted_host, port = parse227(self.sendcmd('PASV')) if self.trust_server_pasv_ipv4_address: host = untrusted_host else: host = self.sock.getpeername()[0] else: host, port = parse229(self.sendcmd('EPSV'), self.sock.getpeername()) return host, port
def __init__(self, host='', user='', passwd='', acct='', keyfile=None, certfile=None, context=None, timeout=_GLOBAL_DEFAULT_TIMEOUT, source_address=None): def __init__(self, host='', user='', passwd='', acct='', keyfile=None, certfile=None, context=None, timeout=_GLOBAL_DEFAULT_TIMEOUT, source_address=None, *, encoding='utf-8'): if context is not None and keyfile is not None: raise ValueError("context and keyfile arguments are mutually " "exclusive")
def login(self, user='', passwd='', acct='', secure=True): if secure and not isinstance(self.sock, ssl.SSLSocket): self.auth() return FTP.login(self, user, passwd, acct) return super().login(user, passwd, acct)
def auth(self): '''Set up secure control connection by using TLS/SSL.'''
def ntransfercmd(self, cmd, rest=None): conn, size = FTP.ntransfercmd(self, cmd, rest) conn, size = super().ntransfercmd(cmd, rest) if self._prot_p: conn = self.context.wrap_socket(conn, server_hostname=self.host)
if resp[:3] != '227': raise error_reply(resp) global _227_re
if resp[:3] != '229': raise error_reply(resp) left = resp.find('(')
if resp[:3] != '257': raise error_reply(resp) if resp[3:5] != ' "':