ftplib.FTP

class ftplib.FTP(host='', user='', passwd='', acct='', timeout=<object object>)[source]

An FTP client class.

To create a connection, call the class using these arguments:
host, user, passwd, acct, timeout

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) If a timeout is passed, then this is now the default timeout for all ftp socket operations for this instance.

Then use self.connect() with optional host and port argument.

To download a file, use ftp.retrlines(‘RETR ‘ + filename), or ftp.retrbinary() with slightly different arguments. To upload a file, use ftp.storlines() or ftp.storbinary(), which have an open file as argument (see their definitions below for details). The download/upload functions first issue appropriate TYPE and PORT or PASV commands.

Methods

__init__([host, user, passwd, acct, timeout])
abort() Abort a file transfer.
acct(password) Send new account name.
close() Close the connection without assuming anything about it.
connect([host, port, timeout]) Connect to host.
cwd(dirname) Change to a directory.
debug(level) Set the debugging level.
delete(filename) Delete a file.
dir(*args) List a directory in long form.
getline()
getmultiline()
getresp()
getwelcome() Get the welcome message from the server.
login([user, passwd, acct]) Login, default anonymous.
makepasv()
makeport() Create a new socket and send a PORT command for it.
mkd(dirname) Make a directory, return its full pathname.
nlst(*args) Return a list of files in a given directory (default the current).
ntransfercmd(cmd[, rest]) Initiate a transfer over the data connection.
putcmd(line)
putline(line)
pwd() Return current working directory.
quit() Quit, and close the connection.
rename(fromname, toname) Rename a file.
retrbinary(cmd, callback[, blocksize, rest]) Retrieve data in binary mode.
retrlines(cmd[, callback]) Retrieve data in line mode.
rmd(dirname) Remove a directory.
sanitize(s)
sendcmd(cmd) Send a command and return the response.
sendeprt(host, port) Send a EPRT command with the current host and the given port number.
sendport(host, port) Send a PORT command with the current host and the given port number.
set_debuglevel(level) Set the debugging level.
set_pasv(val) Use passive or active mode for data transfers.
size(filename) Retrieve the size of a file.
storbinary(cmd, fp[, blocksize, callback, rest]) Store a file in binary mode.
storlines(cmd, fp[, callback]) Store a file in line mode.
transfercmd(cmd[, rest]) Like ntransfercmd() but returns only the socket.
voidcmd(cmd) Send a command and expect a response beginning with ‘2’.
voidresp() Expect a response beginning with ‘2’.