ftplib.FTP
Prev: ftplib.error_temp | Up: ftplib | Next: ftplib.FTP_TLS
Rel: ftplib.error_perm, ftplib.error_proto, ftplib.error_reply, ftplib.error_temp
Ref: docs.python.org — ftplib.FTP
Tags: #public #python3 #stdlib #ftplib
Import
import ftplib
from ftplib import FTP
Signature & Overview
ftplib.FTP(host='', user='', passwd='', acct='', timeout=<object object at 0x1040b4980>, source_address=None, *, encoding='utf-8')
An FTP client class.
Methods & Attributes
FTP.abort(self)— Abort a file transfer. Uses out-of-band data.FTP.acct(self, password)— Send new account name.FTP.close(self)— Close the connection without assuming anything about it.FTP.connect(self, host='', port=0, timeout=-999, source_address=None)— Connect to host. Arguments are: - host: hostname to connect to (string, default previous host) - port: port to connect to (integer, default previous port)FTP.cwd(self, dirname)— Change to a directory.FTP.debug(self, level)— Set the debugging level.FTP.delete(self, filename)— Delete a file.FTP.dir(self, *args)— List a directory in long form.FTP.getline(self)—FTP.getlinemethod/property.FTP.getmultiline(self)—FTP.getmultilinemethod/property.FTP.getresp(self)—FTP.getrespmethod/property.FTP.getwelcome(self)— Get the welcome message from the server.FTP.login(self, user='', passwd='', acct='')— Login, default anonymous.FTP.makepasv(self)— Internal: Does the PASV or EPSV handshake -> (address, port)FTP.makeport(self)— Create a new socket and send a PORT command for it.FTP.mkd(self, dirname)— Make a directory, return its full pathname.FTP.mlsd(self, path='', facts=[])— List a directory in a standardized format by using MLSD command (RFC-3659). If path is omitted the current directory is assumed. "facts" is a list of strings representing the typeFTP.nlst(self, *args)— Return a list of files in a given directory (default the current).FTP.ntransfercmd(self, cmd, rest=None)— Initiate a transfer over the data connection.FTP.putcmd(self, line)—FTP.putcmdmethod/property.FTP.putline(self, line)—FTP.putlinemethod/property.FTP.pwd(self)— Return current working directory.FTP.quit(self)— Quit, and close the connection.FTP.rename(self, fromname, toname)— Rename a file.FTP.retrbinary(self, cmd, callback, blocksize=8192, rest=None)— Retrieve data in binary mode. A new port is created for you.FTP.retrlines(self, cmd, callback=None)— Retrieve data in line mode. A new port is created for you.FTP.rmd(self, dirname)— Remove a directory.FTP.sanitize(self, s)—FTP.sanitizemethod/property.FTP.sendcmd(self, cmd)— Send a command and return the response.FTP.sendeprt(self, host, port)— Send an EPRT command with the current host and the given port number.FTP.sendport(self, host, port)— Send a PORT command with the current host and the given port number.FTP.set_debuglevel(self, level)— Set the debugging level.FTP.set_pasv(self, val)— Use passive or active mode for data transfers.FTP.size(self, filename)— Retrieve the size of a file.FTP.storbinary(self, cmd, fp, blocksize=8192, callback=None, rest=None)— Store a file in binary mode. A new port is created for you.FTP.storlines(self, cmd, fp, callback=None)— Store a file in line mode. A new port is created for you.FTP.transfercmd(self, cmd, rest=None)— Like ntransfercmd() but returns only the socket.FTP.voidcmd(self, cmd)— Send a command and expect a response beginning with '2'.FTP.voidresp(self)— Expect a response beginning with '2'.
Usage
import ftplib
# Plaintext FTP client (avoid on untrusted networks; prefer FTP_TLS or SFTP)
ftp = ftplib.FTP()
assert ftp.port == 21
Gotchas
- Unencrypted: Credentials and file bytes travel in cleartext—use
FTP_TLSwhenever the server supports TLS.
REPL Inspect
from ftplib import FTP
help(FTP)
Linked from
Related notes
- tuts/python3/stdlib_module/ftplib/error_perm Linked here; links to this page; shared tags: #ftplib, #stdlib
- tuts/python3/stdlib_module/ftplib/error_proto Linked here; links to this page; shared tags: #ftplib, #stdlib
- tuts/python3/stdlib_module/ftplib/error_reply Linked here; links to this page; shared tags: #ftplib, #stdlib
- tuts/python3/stdlib_module/ftplib/error_temp Linked here; links to this page; shared tags: #ftplib, #stdlib
- tuts/python3/stdlib_module/ftplib/FTP_TLS Linked here; links to this page; shared tags: #ftplib, #stdlib
- tuts/python3/stdlib_module/ftplib Linked here; links to this page; shared tags: #stdlib
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib
- tuts/c/stdlib/assert/assert shared tags: #stdlib
- tuts/c/stdlib/assert/static_assert shared tags: #stdlib