||An FTP client class.|
To create a connection, call the class using these argument:
host, user, passwd, acct
These are all strings, and have default value ''.
Then use 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.
- __init__(self, host='', user='', passwd='', acct='')
- # Initialization method (called by class instantiation).
# Initialize host to localhost, port to standard ftp port
# Optional arguments are host (for connect()),
# and user, passwd, acct (for login())
- Abort a file transfer. Uses out-of-band data.
This does not follow the procedure from the RFC to send Telnet
IP and Synch; that doesn't seem to work with the servers I've
tried. Instead, just send the ABOR command as OOB data.
- acct(self, password)
- Send new account name.
- Close the connection without assuming anything about it.
- connect(self, host='', port=0)
- Connect to host. Arguments are:
- host: hostname to connect to (string, default previous host)
- port: port to connect to (integer, default previous port)
- cwd(self, dirname)
- Change to a directory.
- debug = set_debuglevel(self, level)
- delete(self, filename)
- Delete a file.
- dir(self, *args)
- List a directory in long form.
By default list current directory to stdout.
Optional last argument is callback function; all
non-empty arguments before it are concatenated to the
LIST command. (This *should* only be used for a pathname.)
- # Internal: return one line from the server, stripping CRLF.
# Raise EOFError if the connection is closed
- # Internal: get a response from the server, which may possibly
# consist of multiple lines. Return a single string with no
# trailing CRLF. If the response consists of multiple lines,
# these are separated by '\n' characters in the string
- # Internal: get a response from the server.
# Raise various errors if the response indicates an error
- Get the welcome message from the server.
(this is read and squirreled away by connect())
- login(self, user='', passwd='', acct='')
- Login, default anonymous.
- Create a new socket and send a PORT command for it.
- mkd(self, dirname)
- Make a directory, return its full pathname.
- nlst(self, *args)
- Return a list of files in a given directory (default the current).
- ntransfercmd(self, cmd, rest=None)
- Initiate a transfer over the data connection.
If the transfer is active, send a port command and the
transfer command, and accept the connection. If the server is
passive, send a pasv command, connect to it, and start the
transfer command. Either way, return the socket for the
connection and the expected size of the transfer. The
expected size may be None if it could not be determined.
Optional `rest' argument can be a string that is sent as the
argument to a RESTART command. This is essentially a server
marker used to tell the server to skip over any data up to the
- putcmd(self, line)
- # Internal: send one command to the server (through putline())
- putline(self, line)
- # Internal: send one line to the server, appending CRLF
- Return current working directory.
- Quit, and close the connection.
- rename(self, fromname, toname)
- Rename a file.
- retrbinary(self, cmd, callback, blocksize=8192, rest=None)
- Retrieve data in binary mode.
`cmd' is a RETR command. `callback' is a callback function is
called for each block. No more than `blocksize' number of
bytes will be read from the socket. Optional `rest' is passed
A new port is created for you. Return the response code.
- retrlines(self, cmd, callback=None)
- Retrieve data in line mode.
The argument is a RETR or LIST command.
The callback function (2nd argument) is called for each line,
with trailing CRLF stripped. This creates a new port for you.
print_line() is the default callback.
- rmd(self, dirname)
- Remove a directory.
- sanitize(self, s)
- # Internal: "sanitize" a string for printing
- sendcmd(self, cmd)
- Send a command and return the response.
- sendport(self, host, port)
- Send a PORT command with the current host and the given
- set_debuglevel(self, level)
- Set the debugging level.
The required argument level means:
0: no debugging output (default)
1: print commands and responses but not body text etc.
2: also print raw lines read and sent before stripping CR/LF
- set_pasv(self, val)
- Use passive or active mode for data transfers.
With a false argument, use the normal PORT mode,
With a true argument, use the PASV command.
- size(self, filename)
- Retrieve the size of a file.
- storbinary(self, cmd, fp, blocksize=8192)
- Store a file in binary mode.
- storlines(self, cmd, fp)
- Store a file in line mode.
- transfercmd(self, cmd, rest=None)
- Like nstransfercmd() but returns only the socket.
- voidcmd(self, cmd)
- Send a command and expect a response beginning with '2'.
- Expect a response beginning with '2'.
||Class to parse & provide access to 'netrc' format files.|
See the netrc(4) man page for information on the file format.
WARNING: This class is obsolete -- use module netrc instead.
- __init__(self, filename=None)
- get_account(self, host)
- Returns login information for the named host.
The return value is a triple containing userid,
password, and the accounting field.
- Return a list of hosts mentioned in the .netrc file.
- get_macro(self, macro)
- Return a sequence of lines which define a named macro.
- Return a list of all defined macro names.