.. versionchanged:: 3.3
*source_address* parameter was added.
+ .. versionchanged:: 3.9
+ If the *timeout* parameter is set to be zero, it will raise a
+ :class:`ValueError` to prevent the creation of a non-blocking socket
.. class:: FTP_TLS(host='', user='', passwd='', acct='', keyfile=None, certfile=None, context=None, timeout=None, source_address=None)
:func:`ssl.create_default_context` select the system's trusted CA
certificates for you.
+ .. versionchanged:: 3.9
+ If the *timeout* parameter is set to be zero, it will raise a
+ :class:`ValueError` to prevent the creation of a non-blocking socket
+
Here's a sample session using the :class:`FTP_TLS` class::
>>> ftps = FTP_TLS('ftp.pureftpd.org')
self.port = port
if timeout != -999:
self.timeout = timeout
+ if self.timeout is not None and not self.timeout:
+ raise ValueError('Non-blocking socket (timeout=0) is not supported')
if source_address is not None:
self.source_address = source_address
sys.audit("ftplib.connect", self, self.host, self.port)
keyfile=keyfile)
self.context = context
self._prot_p = False
- FTP.__init__(self, host, user, passwd, acct, timeout, source_address)
+ super().__init__(host, user, passwd, acct, timeout, source_address)
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.'''
resp = self.voidcmd('AUTH TLS')
else:
resp = self.voidcmd('AUTH SSL')
- self.sock = self.context.wrap_socket(self.sock,
- server_hostname=self.host)
+ self.sock = self.context.wrap_socket(self.sock, server_hostname=self.host)
self.file = self.sock.makefile(mode='r', encoding=self.encoding)
return resp
# --- Overridden FTP methods
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)