Module ftplib :: Class FTP
[show private | hide private]
[frames | no frames]

Class FTP

Known Subclasses:
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 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.

Method Summary
  __init__(self, host, user, passwd, acct)
  abort(self)
Abort a file transfer.
  acct(self, password)
Send new account name.
  close(self)
Close the connection without assuming anything about it.
  connect(self, host, port)
Connect to host.
  cwd(self, dirname)
Change to a directory.
  debug(self, level)
Set the debugging level.
  delete(self, filename)
Delete a file.
  dir(self, *args)
List a directory in long form.
  getline(self)
  getmultiline(self)
  getresp(self)
  getwelcome(self)
Get the welcome message from the server.
  login(self, user, passwd, acct)
Login, default anonymous.
  makepasv(self)
  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, rest)
Initiate a transfer over the data connection.
  putcmd(self, line)
  putline(self, line)
  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, rest)
Retrieve data in binary mode.
  retrlines(self, cmd, callback)
Retrieve data in line mode.
  rmd(self, dirname)
Remove a directory.
  sanitize(self, s)
  sendcmd(self, cmd)
Send a command and return the response.
  sendeprt(self, host, port)
Send a EPRT command with the current host and the given port number.
  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.
  set_pasv(self, val)
Use passive or active mode for data transfers.
  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, rest)
Like ntransfercmd() but returns only the socket.
  voidcmd(self, cmd)
Send a command and expect a response beginning with '2'.
  voidresp(self)
Expect a response beginning with '2'.

Class Variable Summary
int debugging = 0                                                                     
NoneType file = None                                                                  
str host = ''
int passiveserver = 1                                                                     
int port = 21                                                                    
NoneType sock = None                                                                  
NoneType welcome = None                                                                  

Method Details

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(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

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.)

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, 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 given marker.

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, 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 to transfercmd().

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.

sendcmd(self, cmd)

Send a command and return the response.

sendeprt(self, host, port)

Send a EPRT command with the current host and the given port number.

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=8192)

Store a file in binary mode.

storlines(self, cmd, fp)

Store a file in line mode.

transfercmd(self, cmd, rest=None)

Like ntransfercmd() but returns only the socket.

voidcmd(self, cmd)

Send a command and expect a response beginning with '2'.

voidresp(self)

Expect a response beginning with '2'.

Class Variable Details

debugging

Type:
int
Value:
0                                                                     

file

Type:
NoneType
Value:
None                                                                  

host

Type:
str
Value:
''                                                                     

passiveserver

Type:
int
Value:
1                                                                     

port

Type:
int
Value:
21                                                                    

sock

Type:
NoneType
Value:
None                                                                  

welcome

Type:
NoneType
Value:
None                                                                  

Generated by Epydoc 2.1 on Fri Jun 24 12:01:25 2005 http://epydoc.sf.net