Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes
ftplib.FTP Class Reference
Inheritance diagram for ftplib.FTP:
Inheritance graph
[legend]
Collaboration diagram for ftplib.FTP:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def __enter__
def __exit__
def connect
def getwelcome
def set_debuglevel
def set_pasv
def sanitize
def putline
def putcmd
def getline
def getmultiline
def getresp
def voidresp
def abort
def sendcmd
def voidcmd
def sendport
def sendeprt
def makeport
def makepasv
def ntransfercmd
def transfercmd
def login
def retrbinary
def retrlines
def storbinary
def storlines
def acct
def nlst
def dir
def rename
def delete
def cwd
def size
def mkd
def rmd
def pwd
def quit
def close

Public Attributes

 timeout
 host
 af
 debugging
 passiveserver
 lastresp

Static Public Attributes

int debugging = 0
string host = ''
 port = FTP_PORT
 sock = None
 file = None
 welcome = None
int passiveserver = 1
string encoding = "latin1"
 debug = set_debuglevel

Detailed Description

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.

Definition at line 72 of file ftplib.py.


Constructor & Destructor Documentation

def ftplib.FTP.__init__ (   self,
  host = '',
  user = '',
  passwd = '',
  acct = '',
  timeout = _GLOBAL_DEFAULT_TIMEOUT 
)

Definition at line 110 of file ftplib.py.

00110 
00111                  timeout=_GLOBAL_DEFAULT_TIMEOUT):
00112         self.timeout = timeout
00113         if host:
00114             self.connect(host)
00115             if user:
00116                 self.login(user, passwd, acct)

Here is the caller graph for this function:


Member Function Documentation

def ftplib.FTP.__enter__ (   self)

Definition at line 117 of file ftplib.py.

00117 
00118     def __enter__(self):
00119         return self

def ftplib.FTP.__exit__ (   self,
  args 
)

Definition at line 121 of file ftplib.py.

00121 
00122     def __exit__(self, *args):
00123         if self.sock is not None:
00124             try:
00125                 self.quit()
00126             except (socket.error, EOFError):
00127                 pass
00128             finally:
00129                 if self.sock is not None:
00130                     self.close()

Here is the call graph for this function:

Here is the caller graph for this function:

def ftplib.FTP.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.

Reimplemented in ftplib.FTP_TLS.

Definition at line 239 of file ftplib.py.

00239 
00240     def abort(self):
00241         '''Abort a file transfer.  Uses out-of-band data.
00242         This does not follow the procedure from the RFC to send Telnet
00243         IP and Synch; that doesn't seem to work with the servers I've
00244         tried.  Instead, just send the ABOR command as OOB data.'''
00245         line = b'ABOR' + B_CRLF
00246         if self.debugging > 1: print('*put urgent*', self.sanitize(line))
00247         self.sock.sendall(line, MSG_OOB)
00248         resp = self.getmultiline()
00249         if resp[:3] not in {'426', '225', '226'}:
00250             raise error_proto(resp)
00251         return resp

Here is the call graph for this function:

def ftplib.FTP.acct (   self,
  password 
)
Send new account name.

Definition at line 501 of file ftplib.py.

00501 
00502     def acct(self, password):
00503         '''Send new account name.'''
00504         cmd = 'ACCT ' + password
00505         return self.voidcmd(cmd)

Here is the call graph for this function:

def ftplib.FTP.close (   self)
Close the connection without assuming anything about it.

Definition at line 597 of file ftplib.py.

00597 
00598     def close(self):
00599         '''Close the connection without assuming anything about it.'''
00600         if self.file:
00601             self.file.close()
00602             self.sock.close()
00603             self.file = self.sock = None
00604 
00605 
try:
def ftplib.FTP.connect (   self,
  host = '',
  port = 0,
  timeout = -999 
)
Connect to host.  Arguments are:
 - host: hostname to connect to (string, default previous host)
 - port: port to connect to (integer, default previous port)

Definition at line 131 of file ftplib.py.

00131 
00132     def connect(self, host='', port=0, timeout=-999):
00133         '''Connect to host.  Arguments are:
00134          - host: hostname to connect to (string, default previous host)
00135          - port: port to connect to (integer, default previous port)
00136         '''
00137         if host != '':
00138             self.host = host
00139         if port > 0:
00140             self.port = port
00141         if timeout != -999:
00142             self.timeout = timeout
00143         self.sock = socket.create_connection((self.host, self.port), self.timeout)
00144         self.af = self.sock.family
00145         self.file = self.sock.makefile('r', encoding=self.encoding)
00146         self.welcome = self.getresp()
00147         return self.welcome

Here is the caller graph for this function:

def ftplib.FTP.cwd (   self,
  dirname 
)
Change to a directory.

Definition at line 545 of file ftplib.py.

00545 
00546     def cwd(self, dirname):
00547         '''Change to a directory.'''
00548         if dirname == '..':
00549             try:
00550                 return self.voidcmd('CDUP')
00551             except error_perm as msg:
00552                 if msg.args[0][:3] != '500':
00553                     raise
00554         elif dirname == '':
00555             dirname = '.'  # does nothing, but could return error
00556         cmd = 'CWD ' + dirname
00557         return self.voidcmd(cmd)

Here is the call graph for this function:

def ftplib.FTP.delete (   self,
  filename 
)
Delete a file.

Definition at line 537 of file ftplib.py.

00537 
00538     def delete(self, filename):
00539         '''Delete a file.'''
00540         resp = self.sendcmd('DELE ' + filename)
00541         if resp[:3] in {'250', '200'}:
00542             return resp
00543         else:
00544             raise error_reply(resp)

Here is the call graph for this function:

def ftplib.FTP.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.)

Definition at line 515 of file ftplib.py.

00515 
00516     def dir(self, *args):
00517         '''List a directory in long form.
00518         By default list current directory to stdout.
00519         Optional last argument is callback function; all
00520         non-empty arguments before it are concatenated to the
00521         LIST command.  (This *should* only be used for a pathname.)'''
00522         cmd = 'LIST'
00523         func = None
00524         if args[-1:] and type(args[-1]) != type(''):
00525             args, func = args[:-1], args[-1]
00526         for arg in args:
00527             if arg:
00528                 cmd = cmd + (' ' + arg)
00529         self.retrlines(cmd, func)

Here is the call graph for this function:

def ftplib.FTP.getline (   self)

Definition at line 192 of file ftplib.py.

00192 
00193     def getline(self):
00194         line = self.file.readline()
00195         if self.debugging > 1:
00196             print('*get*', self.sanitize(line))
00197         if not line: raise EOFError
00198         if line[-2:] == CRLF: line = line[:-2]
00199         elif line[-1:] in CRLF: line = line[:-1]
00200         return line

Here is the call graph for this function:

Here is the caller graph for this function:

def ftplib.FTP.getmultiline (   self)

Definition at line 205 of file ftplib.py.

00205 
00206     def getmultiline(self):
00207         line = self.getline()
00208         if line[3:4] == '-':
00209             code = line[:3]
00210             while 1:
00211                 nextline = self.getline()
00212                 line = line + ('\n' + nextline)
00213                 if nextline[:3] == code and \
00214                         nextline[3:4] != '-':
00215                     break
00216         return line

Here is the call graph for this function:

Here is the caller graph for this function:

def ftplib.FTP.getresp (   self)

Definition at line 219 of file ftplib.py.

00219 
00220     def getresp(self):
00221         resp = self.getmultiline()
00222         if self.debugging: print('*resp*', self.sanitize(resp))
00223         self.lastresp = resp[:3]
00224         c = resp[:1]
00225         if c in {'1', '2', '3'}:
00226             return resp
00227         if c == '4':
00228             raise error_temp(resp)
00229         if c == '5':
00230             raise error_perm(resp)
00231         raise error_proto(resp)

Here is the call graph for this function:

Here is the caller graph for this function:

def ftplib.FTP.getwelcome (   self)
Get the welcome message from the server.
(this is read and squirreled away by connect())

Definition at line 148 of file ftplib.py.

00148 
00149     def getwelcome(self):
00150         '''Get the welcome message from the server.
00151         (this is read and squirreled away by connect())'''
00152         if self.debugging:
00153             print('*welcome*', self.sanitize(self.welcome))
00154         return self.welcome

Here is the call graph for this function:

def ftplib.FTP.login (   self,
  user = '',
  passwd = '',
  acct = '' 
)
Login, default anonymous.

Definition at line 381 of file ftplib.py.

00381 
00382     def login(self, user = '', passwd = '', acct = ''):
00383         '''Login, default anonymous.'''
00384         if not user: user = 'anonymous'
00385         if not passwd: passwd = ''
00386         if not acct: acct = ''
00387         if user == 'anonymous' and passwd in {'', '-'}:
00388             # If there is no anonymous ftp password specified
00389             # then we'll just use anonymous@
00390             # We don't send any other thing because:
00391             # - We want to remain anonymous
00392             # - We want to stop SPAM
00393             # - We don't want to let ftp sites to discriminate by the user,
00394             #   host or country.
00395             passwd = passwd + 'anonymous@'
00396         resp = self.sendcmd('USER ' + user)
00397         if resp[0] == '3': resp = self.sendcmd('PASS ' + passwd)
00398         if resp[0] == '3': resp = self.sendcmd('ACCT ' + acct)
00399         if resp[0] != '2':
00400             raise error_reply(resp)
00401         return resp

Here is the call graph for this function:

def ftplib.FTP.makepasv (   self)

Definition at line 313 of file ftplib.py.

00313 
00314     def makepasv(self):
00315         if self.af == socket.AF_INET:
00316             host, port = parse227(self.sendcmd('PASV'))
00317         else:
00318             host, port = parse229(self.sendcmd('EPSV'), self.sock.getpeername())
00319         return host, port

Here is the call graph for this function:

Here is the caller graph for this function:

def ftplib.FTP.makeport (   self)
Create a new socket and send a PORT command for it.

Definition at line 285 of file ftplib.py.

00285 
00286     def makeport(self):
00287         '''Create a new socket and send a PORT command for it.'''
00288         msg = "getaddrinfo returns an empty list"
00289         sock = None
00290         for res in socket.getaddrinfo(None, 0, self.af, socket.SOCK_STREAM, 0, socket.AI_PASSIVE):
00291             af, socktype, proto, canonname, sa = res
00292             try:
00293                 sock = socket.socket(af, socktype, proto)
00294                 sock.bind(sa)
00295             except socket.error as msg:
00296                 if sock:
00297                     sock.close()
00298                 sock = None
00299                 continue
00300             break
00301         if not sock:
00302             raise socket.error(msg)
00303         sock.listen(1)
00304         port = sock.getsockname()[1] # Get proper port
00305         host = self.sock.getsockname()[0] # Get proper host
00306         if self.af == socket.AF_INET:
00307             resp = self.sendport(host, port)
00308         else:
00309             resp = self.sendeprt(host, port)
00310         if self.timeout is not _GLOBAL_DEFAULT_TIMEOUT:
00311             sock.settimeout(self.timeout)
00312         return sock

Here is the call graph for this function:

Here is the caller graph for this function:

def ftplib.FTP.mkd (   self,
  dirname 
)
Make a directory, return its full pathname.

Definition at line 569 of file ftplib.py.

00569 
00570     def mkd(self, dirname):
00571         '''Make a directory, return its full pathname.'''
00572         resp = self.voidcmd('MKD ' + dirname)
00573         # fix around non-compliant implementations such as IIS shipped
00574         # with Windows server 2003
00575         if not resp.startswith('257'):
00576             return ''
00577         return parse257(resp)

Here is the call graph for this function:

def ftplib.FTP.nlst (   self,
  args 
)
Return a list of files in a given directory (default the current).

Definition at line 506 of file ftplib.py.

00506 
00507     def nlst(self, *args):
00508         '''Return a list of files in a given directory (default the current).'''
00509         cmd = 'NLST'
00510         for arg in args:
00511             cmd = cmd + (' ' + arg)
00512         files = []
00513         self.retrlines(cmd, files.append)
00514         return files

Here is the call graph for this function:

def ftplib.FTP.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 REST command.  This is essentially a server
marker used to tell the server to skip over any data up to the
given marker.

Reimplemented in ftplib.FTP_TLS.

Definition at line 320 of file ftplib.py.

00320 
00321     def ntransfercmd(self, cmd, rest=None):
00322         """Initiate a transfer over the data connection.
00323 
00324         If the transfer is active, send a port command and the
00325         transfer command, and accept the connection.  If the server is
00326         passive, send a pasv command, connect to it, and start the
00327         transfer command.  Either way, return the socket for the
00328         connection and the expected size of the transfer.  The
00329         expected size may be None if it could not be determined.
00330 
00331         Optional `rest' argument can be a string that is sent as the
00332         argument to a REST command.  This is essentially a server
00333         marker used to tell the server to skip over any data up to the
00334         given marker.
00335         """
00336         size = None
00337         if self.passiveserver:
00338             host, port = self.makepasv()
00339             conn = socket.create_connection((host, port), self.timeout)
00340             try:
00341                 if rest is not None:
00342                     self.sendcmd("REST %s" % rest)
00343                 resp = self.sendcmd(cmd)
00344                 # Some servers apparently send a 200 reply to
00345                 # a LIST or STOR command, before the 150 reply
00346                 # (and way before the 226 reply). This seems to
00347                 # be in violation of the protocol (which only allows
00348                 # 1xx or error messages for LIST), so we just discard
00349                 # this response.
00350                 if resp[0] == '2':
00351                     resp = self.getresp()
00352                 if resp[0] != '1':
00353                     raise error_reply(resp)
00354             except:
00355                 conn.close()
00356                 raise
00357         else:
00358             sock = self.makeport()
00359             try:
00360                 if rest is not None:
00361                     self.sendcmd("REST %s" % rest)
00362                 resp = self.sendcmd(cmd)
00363                 # See above.
00364                 if resp[0] == '2':
00365                     resp = self.getresp()
00366                 if resp[0] != '1':
00367                     raise error_reply(resp)
00368                 conn, sockaddr = sock.accept()
00369                 if self.timeout is not _GLOBAL_DEFAULT_TIMEOUT:
00370                     conn.settimeout(self.timeout)
00371             finally:
00372                 sock.close()
00373         if resp[:3] == '150':
00374             # this is conditional in case we received a 125
00375             size = parse150(resp)
00376         return conn, size

Here is the call graph for this function:

Here is the caller graph for this function:

def ftplib.FTP.putcmd (   self,
  line 
)

Definition at line 186 of file ftplib.py.

00186 
00187     def putcmd(self, line):
00188         if self.debugging: print('*cmd*', self.sanitize(line))
00189         self.putline(line)

Here is the call graph for this function:

Here is the caller graph for this function:

def ftplib.FTP.putline (   self,
  line 
)

Definition at line 180 of file ftplib.py.

00180 
00181     def putline(self, line):
00182         line = line + CRLF
00183         if self.debugging > 1: print('*put*', self.sanitize(line))
00184         self.sock.sendall(line.encode(self.encoding))

Here is the call graph for this function:

Here is the caller graph for this function:

def ftplib.FTP.pwd (   self)
Return current working directory.

Definition at line 582 of file ftplib.py.

00582 
00583     def pwd(self):
00584         '''Return current working directory.'''
00585         resp = self.voidcmd('PWD')
00586         # fix around non-compliant implementations such as IIS shipped
00587         # with Windows server 2003
00588         if not resp.startswith('257'):
00589             return ''
00590         return parse257(resp)

Here is the call graph for this function:

def ftplib.FTP.quit (   self)
Quit, and close the connection.

Definition at line 591 of file ftplib.py.

00591 
00592     def quit(self):
00593         '''Quit, and close the connection.'''
00594         resp = self.voidcmd('QUIT')
00595         self.close()
00596         return resp

Here is the call graph for this function:

Here is the caller graph for this function:

def ftplib.FTP.rename (   self,
  fromname,
  toname 
)
Rename a file.

Definition at line 530 of file ftplib.py.

00530 
00531     def rename(self, fromname, toname):
00532         '''Rename a file.'''
00533         resp = self.sendcmd('RNFR ' + fromname)
00534         if resp[0] != '3':
00535             raise error_reply(resp)
00536         return self.voidcmd('RNTO ' + toname)

Here is the call graph for this function:

def ftplib.FTP.retrbinary (   self,
  cmd,
  callback,
  blocksize = 8192,
  rest = None 
)
Retrieve data in binary mode.  A new port is created for you.

Args:
  cmd: A RETR command.
  callback: A single parameter callable to be called on each
    block of data read.
  blocksize: The maximum number of bytes to read from the
     socket at one time.  [default: 8192]
  rest: Passed to transfercmd().  [default: None]

Returns:
  The response code.

Reimplemented in ftplib.FTP_TLS.

Definition at line 402 of file ftplib.py.

00402 
00403     def retrbinary(self, cmd, callback, blocksize=8192, rest=None):
00404         """Retrieve data in binary mode.  A new port is created for you.
00405 
00406         Args:
00407           cmd: A RETR command.
00408           callback: A single parameter callable to be called on each
00409                     block of data read.
00410           blocksize: The maximum number of bytes to read from the
00411                      socket at one time.  [default: 8192]
00412           rest: Passed to transfercmd().  [default: None]
00413 
00414         Returns:
00415           The response code.
00416         """
00417         self.voidcmd('TYPE I')
00418         with self.transfercmd(cmd, rest) as conn:
00419             while 1:
00420                 data = conn.recv(blocksize)
00421                 if not data:
00422                     break
00423                 callback(data)
00424         return self.voidresp()

Here is the call graph for this function:

def ftplib.FTP.retrlines (   self,
  cmd,
  callback = None 
)
Retrieve data in line mode.  A new port is created for you.

Args:
  cmd: A RETR, LIST, NLST, or MLSD command.
  callback: An optional single parameter callable that is called
    for each line with the trailing CRLF stripped.
    [default: print_line()]

Returns:
  The response code.

Reimplemented in ftplib.FTP_TLS.

Definition at line 425 of file ftplib.py.

00425 
00426     def retrlines(self, cmd, callback = None):
00427         """Retrieve data in line mode.  A new port is created for you.
00428 
00429         Args:
00430           cmd: A RETR, LIST, NLST, or MLSD command.
00431           callback: An optional single parameter callable that is called
00432                     for each line with the trailing CRLF stripped.
00433                     [default: print_line()]
00434 
00435         Returns:
00436           The response code.
00437         """
00438         if callback is None: callback = print_line
00439         resp = self.sendcmd('TYPE A')
00440         with self.transfercmd(cmd) as conn, \
00441                  conn.makefile('r', encoding=self.encoding) as fp:
00442             while 1:
00443                 line = fp.readline()
00444                 if self.debugging > 2: print('*retr*', repr(line))
00445                 if not line:
00446                     break
00447                 if line[-2:] == CRLF:
00448                     line = line[:-2]
00449                 elif line[-1:] == '\n':
00450                     line = line[:-1]
00451                 callback(line)
00452         return self.voidresp()

Here is the call graph for this function:

Here is the caller graph for this function:

def ftplib.FTP.rmd (   self,
  dirname 
)
Remove a directory.

Definition at line 578 of file ftplib.py.

00578 
00579     def rmd(self, dirname):
00580         '''Remove a directory.'''
00581         return self.voidcmd('RMD ' + dirname)

Here is the call graph for this function:

def ftplib.FTP.sanitize (   self,
  s 
)

Definition at line 171 of file ftplib.py.

00171 
00172     def sanitize(self, s):
00173         if s[:5] == 'pass ' or s[:5] == 'PASS ':
00174             i = len(s)
00175             while i > 5 and s[i-1] in {'\r', '\n'}:
00176                 i = i-1
00177             s = s[:5] + '*'*(i-5) + s[i:]
00178         return repr(s)

Here is the caller graph for this function:

def ftplib.FTP.sendcmd (   self,
  cmd 
)
Send a command and return the response.

Definition at line 252 of file ftplib.py.

00252 
00253     def sendcmd(self, cmd):
00254         '''Send a command and return the response.'''
00255         self.putcmd(cmd)
00256         return self.getresp()

Here is the call graph for this function:

Here is the caller graph for this function:

def ftplib.FTP.sendeprt (   self,
  host,
  port 
)
Send a EPRT command with the current host and the given port number.

Definition at line 272 of file ftplib.py.

00272 
00273     def sendeprt(self, host, port):
00274         '''Send a EPRT command with the current host and the given port number.'''
00275         af = 0
00276         if self.af == socket.AF_INET:
00277             af = 1
00278         if self.af == socket.AF_INET6:
00279             af = 2
00280         if af == 0:
00281             raise error_proto('unsupported address family')
00282         fields = ['', repr(af), host, repr(port), '']
00283         cmd = 'EPRT ' + '|'.join(fields)
00284         return self.voidcmd(cmd)

Here is the call graph for this function:

Here is the caller graph for this function:

def ftplib.FTP.sendport (   self,
  host,
  port 
)
Send a PORT command with the current host and the given
port number.

Definition at line 262 of file ftplib.py.

00262 
00263     def sendport(self, host, port):
00264         '''Send a PORT command with the current host and the given
00265         port number.
00266         '''
00267         hbytes = host.split('.')
00268         pbytes = [repr(port//256), repr(port%256)]
00269         bytes = hbytes + pbytes
00270         cmd = 'PORT ' + ','.join(bytes)
00271         return self.voidcmd(cmd)

Here is the call graph for this function:

Here is the caller graph for this function:

def ftplib.FTP.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

Definition at line 155 of file ftplib.py.

00155 
00156     def set_debuglevel(self, level):
00157         '''Set the debugging level.
00158         The required argument level means:
00159         0: no debugging output (default)
00160         1: print commands and responses but not body text etc.
00161         2: also print raw lines read and sent before stripping CR/LF'''
        self.debugging = level
def ftplib.FTP.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.

Definition at line 164 of file ftplib.py.

00164 
00165     def set_pasv(self, val):
00166         '''Use passive or active mode for data transfers.
00167         With a false argument, use the normal PORT mode,
00168         With a true argument, use the PASV command.'''
00169         self.passiveserver = val

def ftplib.FTP.size (   self,
  filename 
)
Retrieve the size of a file.

Definition at line 558 of file ftplib.py.

00558 
00559     def size(self, filename):
00560         '''Retrieve the size of a file.'''
00561         # The SIZE command is defined in RFC-3659
00562         resp = self.sendcmd('SIZE ' + filename)
00563         if resp[:3] == '213':
00564             s = resp[3:].strip()
00565             try:
00566                 return int(s)
00567             except (OverflowError, ValueError):
00568                 return int(s)

Here is the call graph for this function:

def ftplib.FTP.storbinary (   self,
  cmd,
  fp,
  blocksize = 8192,
  callback = None,
  rest = None 
)
Store a file in binary mode.  A new port is created for you.

Args:
  cmd: A STOR command.
  fp: A file-like object with a read(num_bytes) method.
  blocksize: The maximum data size to read from fp and send over
     the connection at once.  [default: 8192]
  callback: An optional single parameter callable that is called on
    on each block of data after it is sent.  [default: None]
  rest: Passed to transfercmd().  [default: None]

Returns:
  The response code.

Reimplemented in ftplib.FTP_TLS.

Definition at line 453 of file ftplib.py.

00453 
00454     def storbinary(self, cmd, fp, blocksize=8192, callback=None, rest=None):
00455         """Store a file in binary mode.  A new port is created for you.
00456 
00457         Args:
00458           cmd: A STOR command.
00459           fp: A file-like object with a read(num_bytes) method.
00460           blocksize: The maximum data size to read from fp and send over
00461                      the connection at once.  [default: 8192]
00462           callback: An optional single parameter callable that is called on
00463                     on each block of data after it is sent.  [default: None]
00464           rest: Passed to transfercmd().  [default: None]
00465 
00466         Returns:
00467           The response code.
00468         """
00469         self.voidcmd('TYPE I')
00470         with self.transfercmd(cmd, rest) as conn:
00471             while 1:
00472                 buf = fp.read(blocksize)
00473                 if not buf: break
00474                 conn.sendall(buf)
00475                 if callback: callback(buf)
00476         return self.voidresp()

Here is the call graph for this function:

def ftplib.FTP.storlines (   self,
  cmd,
  fp,
  callback = None 
)
Store a file in line mode.  A new port is created for you.

Args:
  cmd: A STOR command.
  fp: A file-like object with a readline() method.
  callback: An optional single parameter callable that is called on
    on each line after it is sent.  [default: None]

Returns:
  The response code.

Reimplemented in ftplib.FTP_TLS.

Definition at line 477 of file ftplib.py.

00477 
00478     def storlines(self, cmd, fp, callback=None):
00479         """Store a file in line mode.  A new port is created for you.
00480 
00481         Args:
00482           cmd: A STOR command.
00483           fp: A file-like object with a readline() method.
00484           callback: An optional single parameter callable that is called on
00485                     on each line after it is sent.  [default: None]
00486 
00487         Returns:
00488           The response code.
00489         """
00490         self.voidcmd('TYPE A')
00491         with self.transfercmd(cmd) as conn:
00492             while 1:
00493                 buf = fp.readline()
00494                 if not buf: break
00495                 if buf[-2:] != B_CRLF:
00496                     if buf[-1] in B_CRLF: buf = buf[:-1]
00497                     buf = buf + B_CRLF
00498                 conn.sendall(buf)
00499                 if callback: callback(buf)
00500         return self.voidresp()

Here is the call graph for this function:

def ftplib.FTP.transfercmd (   self,
  cmd,
  rest = None 
)
Like ntransfercmd() but returns only the socket.

Definition at line 377 of file ftplib.py.

00377 
00378     def transfercmd(self, cmd, rest=None):
00379         """Like ntransfercmd() but returns only the socket."""
00380         return self.ntransfercmd(cmd, rest)[0]

Here is the call graph for this function:

Here is the caller graph for this function:

def ftplib.FTP.voidcmd (   self,
  cmd 
)
Send a command and expect a response beginning with '2'.

Definition at line 257 of file ftplib.py.

00257 
00258     def voidcmd(self, cmd):
00259         """Send a command and expect a response beginning with '2'."""
00260         self.putcmd(cmd)
00261         return self.voidresp()

Here is the call graph for this function:

Here is the caller graph for this function:

def ftplib.FTP.voidresp (   self)
Expect a response beginning with '2'.

Definition at line 232 of file ftplib.py.

00232 
00233     def voidresp(self):
00234         """Expect a response beginning with '2'."""
00235         resp = self.getresp()
00236         if resp[:1] != '2':
00237             raise error_reply(resp)
00238         return resp

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 143 of file ftplib.py.

Definition at line 162 of file ftplib.py.

int ftplib.FTP.debugging = 0 [static]

Definition at line 96 of file ftplib.py.

Definition at line 161 of file ftplib.py.

string ftplib.FTP.encoding = "latin1" [static]

Definition at line 103 of file ftplib.py.

ftplib.FTP.file = None [static]

Reimplemented in ftplib.FTP_TLS.

Definition at line 100 of file ftplib.py.

string ftplib.FTP.host = '' [static]

Definition at line 97 of file ftplib.py.

Definition at line 137 of file ftplib.py.

Definition at line 222 of file ftplib.py.

Definition at line 102 of file ftplib.py.

Definition at line 168 of file ftplib.py.

Definition at line 98 of file ftplib.py.

ftplib.FTP.sock = None [static]

Reimplemented in ftplib.FTP_TLS.

Definition at line 99 of file ftplib.py.

Definition at line 111 of file ftplib.py.

ftplib.FTP.welcome = None [static]

Definition at line 101 of file ftplib.py.


The documentation for this class was generated from the following file: