neurotic.datasets.ftpauth¶
The neurotic.datasets.ftpauth module implements a
urllib.request-compatible FTP handler that prompts for and remembers
passwords.
-
class
neurotic.datasets.ftpauth.FTPBasicAuthHandler(password_mgr=None)[source]¶ This subclass of
urllib.request.FTPHandlerimplements basic authentication management for FTP connections. Likeurllib.request.HTTPBasicAuthHandler, this handler for FTP connections has a password manager that it checks for login credentials before connecting to a server.This subclass also ensures that file size is included in the response header, which can fail for some FTP servers if the original
FTPHandleris used.This handler can be installed globally in a Python session so that calls to
urllib.request.urlopen('ftp://...')will use it automatically:>>> handler = FTPBasicAuthHandler() >>> handler.add_password(None, uri, user, passwd) # realm must be None >>> opener = urllib.request.build_opener(handler) >>> urllib.request.install_opener(opener)
-
neurotic.datasets.ftpauth.setup_ftpauth()[source]¶ Install
neurotic.datasets.ftpauth.FTPBasicAuthHandleras the global default FTP handler.Note that
urllib.request.install_opener()used here will remove all other non-default handlers installed in a different opener, such as anurllib.request.HTTPBasicAuthHandler.