PyDocs

Nav

Internet Protocols and Support

FTP

ftplib

class (source) not WASI
  • FTP(host='', user='', passwd='', acct='', timeout=None, source_address=None, *, encoding='utf-8')
An FTP client class.

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

The first four arguments are all strings, and have default value ''.
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.

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.
Changed in 3.2, 3.3, 3.9
  • 3.2: Support for the with statement was added.
  • 3.3: source_address parameter was added.
  • 3.9: If the timeout parameter is set to be zero, it will raise a ValueError to prevent the creation of a non-blocking socket. The encoding parameter was added, and the default was changed from Latin-1 to UTF-8 to follow RFC 2640.
Members of FTP

a

abort
Abort a file transfer.

c

close
Close the connection without assuming anything about it.
connect
Connect to host.
cwd
Change to a directory.

d

delete
Delete a file.
dir
List a directory in long form.

g

getwelcome
Get the welcome message from the server.

l

login
Login, default anonymous.

m

mkd
Make a directory, return its full pathname.
mlsd
List a directory in a standardized format by using MLSD command (RFC-3659).

n

nlst
Return a list of files in a given directory (default the current).
ntransfercmd
Initiate a transfer over the data connection.

p

pwd
Return current working directory.

q

quit
Quit, and close the connection.

r

rename
Rename a file.
retrbinary
Retrieve data in binary mode.
retrlines
Retrieve data in line mode.
rmd
Remove a directory.

s

sendcmd
Send a command and return the response.
set_debuglevel
Set the debugging level.
set_pasv
Use passive or active mode for data transfers.
size
Retrieve the size of a file.
storbinary
Store a file in binary mode.
storlines
Store a file in line mode.

t

transfercmd
Like ntransfercmd() but returns only the socket.

v

voidcmd
Send a command and expect a response beginning with '2'.
1 Example
>>> from ftplib import FTP
>>> with FTP("ftp1.at.proftpd.org") as ftp:
...     ftp.login()
...     ftp.dir()
...
'230 Anonymous login ok, restrictions apply.'
dr-xr-xr-x   9 ftp      ftp           154 May  6 10:43 .
dr-xr-xr-x   9 ftp      ftp           154 May  6 10:43 ..
dr-xr-xr-x   5 ftp      ftp          4096 May  6 10:43 CentOS
dr-xr-xr-x   3 ftp      ftp            18 Jul 10  2008 Fedora
>>>
from the Python docs
See Also
No see-alsos for ftplib/FTP
0 Notes
No notes for FTP