|
|
- FTP
- Netrc
class FTP |
|
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(self)
- 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(self)
- 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.)
- getline(self)
- # Internal: return one line from the server, stripping CRLF.
# Raise EOFError if the connection is closed
- getmultiline(self)
- # 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
- getresp(self)
- # Internal: get a response from the server.
# Raise various errors if the response indicates an error
- getwelcome(self)
- Get the welcome message from the server.
(this is read and squirreled away by connect())
- login(self, user='', passwd='', acct='')
- Login, default anonymous.
- makeport(self)
- 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)
- 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.
- putcmd(self, line)
- # Internal: send one command to the server (through putline())
- putline(self, line)
- # Internal: send one line to the server, appending CRLF
- pwd(self)
- Return current working directory.
- quit(self)
- Quit, and close the connection.
- rename(self, fromname, toname)
- Rename a file.
- retrbinary(self, cmd, callback, blocksize=8192)
- Retrieve data in binary mode.
The argument is a RETR command.
The callback function is called for each block.
This creates a new port for you
- 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 port number.
- 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)
- Store a file in binary mode.
- storlines(self, cmd, fp)
- Store a file in line mode.
- transfercmd(self, cmd)
- Initiate a transfer over the data connection. Returns
the socket for the connection. See also ntransfercmd().
- voidcmd(self, cmd)
- Send a command and expect a response beginning with '2'.
- voidresp(self)
- Expect a response beginning with '2'.
|
class Netrc |
|
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.
- get_hosts(self)
- Return a list of hosts mentioned in the .netrc file.
- get_macro(self, macro)
- Return a sequence of lines which define a named macro.
- get_macros(self)
- Return a list of all defined macro names.
|
|