Back to index

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

List of all members.

Public Member Functions

def __init__
def login
def auth
def prot_p
def prot_c
def ntransfercmd
def retrbinary
def retrlines
def storbinary
def storlines
def abort
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 sendcmd
def voidcmd
def sendport
def sendeprt
def makeport
def makepasv
def transfercmd
def login
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

 keyfile
 certfile
 context
 sock
 file
 debugging
 host
 passiveserver
 timeout
 af
 lastresp

Static Public Attributes

 ssl_version = ssl.PROTOCOL_TLSv1
int debugging = 0
string host = ''
 port = FTP_PORT
 welcome = None
int passiveserver = 1
string encoding = "latin1"
 debug = set_debuglevel

Private Attributes

 _prot_p

Detailed Description

A FTP subclass which adds TLS support to FTP as described
in RFC-4217.

Connect as usual to port 21 implicitly securing the FTP control
connection before authenticating.

Securing the data connection requires user to explicitly ask
for it by calling prot_p() method.

Usage example:
>>> from ftplib import FTP_TLS
>>> ftps = FTP_TLS('ftp.python.org')
>>> ftps.login()  # login anonymously previously securing control channel
'230 Guest login ok, access restrictions apply.'
>>> ftps.prot_p()  # switch to secure data connection
'200 Protection level set to P'
>>> ftps.retrlines('LIST')  # list directory content securely
total 9
drwxr-xr-x   8 root     wheel        1024 Jan  3  1994 .
drwxr-xr-x   8 root     wheel        1024 Jan  3  1994 ..
drwxr-xr-x   2 root     wheel        1024 Jan  3  1994 bin
drwxr-xr-x   2 root     wheel        1024 Jan  3  1994 etc
d-wxrwxr-x   2 ftp      wheel        1024 Sep  5 13:43 incoming
drwxr-xr-x   2 root     wheel        1024 Nov 17  1993 lib
drwxr-xr-x   6 1094     wheel        1024 Sep 13 19:07 pub
drwxr-xr-x   3 root     wheel        1024 Jan  3  1994 usr
-rw-r--r--   1 root     root          312 Aug  1  1994 welcome.msg
'226 Transfer complete.'
>>> ftps.quit()
'221 Goodbye.'
>>>

Definition at line 610 of file ftplib.py.


Constructor & Destructor Documentation

def ftplib.FTP_TLS.__init__ (   self,
  host = '',
  user = '',
  passwd = '',
  acct = '',
  keyfile = None,
  certfile = None,
  context = None,
  timeout = _GLOBAL_DEFAULT_TIMEOUT 
)

Definition at line 647 of file ftplib.py.

00647 
00648                      timeout=_GLOBAL_DEFAULT_TIMEOUT):
00649             if context is not None and keyfile is not None:
00650                 raise ValueError("context and keyfile arguments are mutually "
00651                                  "exclusive")
00652             if context is not None and certfile is not None:
00653                 raise ValueError("context and certfile arguments are mutually "
00654                                  "exclusive")
00655             self.keyfile = keyfile
00656             self.certfile = certfile
00657             self.context = context
00658             self._prot_p = False
00659             FTP.__init__(self, host, user, passwd, acct, timeout)

Here is the caller graph for this function:


Member Function Documentation

def ftplib.FTP.__enter__ (   self) [inherited]

Definition at line 117 of file ftplib.py.

00117 
00118     def __enter__(self):
00119         return self

def ftplib.FTP.__exit__ (   self,
  args 
) [inherited]

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_TLS.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 from ftplib.FTP.

Definition at line 791 of file ftplib.py.

00791 
00792         def abort(self):
00793             # overridden as we can't pass MSG_OOB flag to sendall()
00794             line = b'ABOR' + B_CRLF
00795             self.sock.sendall(line)
00796             resp = self.getmultiline()
00797             if resp[:3] not in {'426', '225', '226'}:
00798                 raise error_proto(resp)
00799             return resp
00800 
    __all__.append('FTP_TLS')

Here is the call graph for this function:

def ftplib.FTP.acct (   self,
  password 
) [inherited]
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_TLS.auth (   self)
Set up secure control connection by using TLS/SSL.

Definition at line 665 of file ftplib.py.

00665 
00666         def auth(self):
00667             '''Set up secure control connection by using TLS/SSL.'''
00668             if isinstance(self.sock, ssl.SSLSocket):
00669                 raise ValueError("Already using TLS")
00670             if self.ssl_version == ssl.PROTOCOL_TLSv1:
00671                 resp = self.voidcmd('AUTH TLS')
00672             else:
00673                 resp = self.voidcmd('AUTH SSL')
00674             if self.context is not None:
00675                 self.sock = self.context.wrap_socket(self.sock)
00676             else:
00677                 self.sock = ssl.wrap_socket(self.sock, self.keyfile,
00678                                             self.certfile,
00679                                             ssl_version=self.ssl_version)
00680             self.file = self.sock.makefile(mode='r', encoding=self.encoding)
00681             return resp

Here is the call graph for this function:

Here is the caller graph for this function:

def ftplib.FTP.close (   self) [inherited]
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 
) [inherited]
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 
) [inherited]
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 
) [inherited]
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 
) [inherited]
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) [inherited]

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) [inherited]

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) [inherited]

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) [inherited]
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 = '' 
) [inherited]
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_TLS.login (   self,
  user = '',
  passwd = '',
  acct = '',
  secure = True 
)

Definition at line 660 of file ftplib.py.

00660 
00661         def login(self, user='', passwd='', acct='', secure=True):
00662             if secure and not isinstance(self.sock, ssl.SSLSocket):
00663                 self.auth()
00664             return FTP.login(self, user, passwd, acct)

Here is the call graph for this function:

def ftplib.FTP.makepasv (   self) [inherited]

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) [inherited]
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 
) [inherited]
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 
) [inherited]
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_TLS.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 from ftplib.FTP.

Definition at line 706 of file ftplib.py.

00706 
00707         def ntransfercmd(self, cmd, rest=None):
00708             conn, size = FTP.ntransfercmd(self, cmd, rest)
00709             if self._prot_p:
00710                 if self.context is not None:
00711                     conn = self.context.wrap_socket(conn)
00712                 else:
00713                     conn = ssl.wrap_socket(conn, self.keyfile, self.certfile,
00714                                            ssl_version=self.ssl_version)
00715             return conn, size

Here is the call graph for this function:

def ftplib.FTP_TLS.prot_c (   self)
Set up clear text data connection.

Definition at line 698 of file ftplib.py.

00698 
00699         def prot_c(self):
00700             '''Set up clear text data connection.'''
00701             resp = self.voidcmd('PROT C')
00702             self._prot_p = False
00703             return resp

Here is the call graph for this function:

def ftplib.FTP_TLS.prot_p (   self)
Set up secure data connection.

Definition at line 682 of file ftplib.py.

00682 
00683         def prot_p(self):
00684             '''Set up secure data connection.'''
00685             # PROT defines whether or not the data channel is to be protected.
00686             # Though RFC-2228 defines four possible protection levels,
00687             # RFC-4217 only recommends two, Clear and Private.
00688             # Clear (PROT C) means that no security is to be used on the
00689             # data-channel, Private (PROT P) means that the data-channel
00690             # should be protected by TLS.
00691             # PBSZ command MUST still be issued, but must have a parameter of
00692             # '0' to indicate that no buffering is taking place and the data
00693             # connection should not be encapsulated.
00694             self.voidcmd('PBSZ 0')
00695             resp = self.voidcmd('PROT P')
00696             self._prot_p = True
00697             return resp

Here is the call graph for this function:

def ftplib.FTP.putcmd (   self,
  line 
) [inherited]

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 
) [inherited]

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) [inherited]
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) [inherited]
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 
) [inherited]
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_TLS.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 from ftplib.FTP.

Definition at line 716 of file ftplib.py.

00716 
00717         def retrbinary(self, cmd, callback, blocksize=8192, rest=None):
00718             self.voidcmd('TYPE I')
00719             conn = self.transfercmd(cmd, rest)
00720             try:
00721                 while 1:
00722                     data = conn.recv(blocksize)
00723                     if not data:
00724                         break
00725                     callback(data)
00726                 # shutdown ssl layer
00727                 if isinstance(conn, ssl.SSLSocket):
00728                     conn.unwrap()
00729             finally:
00730                 conn.close()
00731             return self.voidresp()

Here is the call graph for this function:

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

Definition at line 732 of file ftplib.py.

00732 
00733         def retrlines(self, cmd, callback = None):
00734             if callback is None: callback = print_line
00735             resp = self.sendcmd('TYPE A')
00736             conn = self.transfercmd(cmd)
00737             fp = conn.makefile('r', encoding=self.encoding)
00738             try:
00739                 while 1:
00740                     line = fp.readline()
00741                     if self.debugging > 2: print('*retr*', repr(line))
00742                     if not line:
00743                         break
00744                     if line[-2:] == CRLF:
00745                         line = line[:-2]
00746                     elif line[-1:] == '\n':
00747                         line = line[:-1]
00748                     callback(line)
00749                 # shutdown ssl layer
00750                 if isinstance(conn, ssl.SSLSocket):
00751                     conn.unwrap()
00752             finally:
00753                 fp.close()
00754                 conn.close()
00755             return self.voidresp()

Here is the call graph for this function:

def ftplib.FTP.rmd (   self,
  dirname 
) [inherited]
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 
) [inherited]

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 
) [inherited]
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 
) [inherited]
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 
) [inherited]
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 
) [inherited]
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 
) [inherited]
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 
) [inherited]
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_TLS.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 from ftplib.FTP.

Definition at line 756 of file ftplib.py.

00756 
00757         def storbinary(self, cmd, fp, blocksize=8192, callback=None, rest=None):
00758             self.voidcmd('TYPE I')
00759             conn = self.transfercmd(cmd, rest)
00760             try:
00761                 while 1:
00762                     buf = fp.read(blocksize)
00763                     if not buf: break
00764                     conn.sendall(buf)
00765                     if callback: callback(buf)
00766                 # shutdown ssl layer
00767                 if isinstance(conn, ssl.SSLSocket):
00768                     conn.unwrap()
00769             finally:
00770                 conn.close()
00771             return self.voidresp()

Here is the call graph for this function:

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

Definition at line 772 of file ftplib.py.

00772 
00773         def storlines(self, cmd, fp, callback=None):
00774             self.voidcmd('TYPE A')
00775             conn = self.transfercmd(cmd)
00776             try:
00777                 while 1:
00778                     buf = fp.readline()
00779                     if not buf: break
00780                     if buf[-2:] != B_CRLF:
00781                         if buf[-1] in B_CRLF: buf = buf[:-1]
00782                         buf = buf + B_CRLF
00783                     conn.sendall(buf)
00784                     if callback: callback(buf)
00785                 # shutdown ssl layer
00786                 if isinstance(conn, ssl.SSLSocket):
00787                     conn.unwrap()
00788             finally:
00789                 conn.close()
00790             return self.voidresp()

Here is the call graph for this function:

def ftplib.FTP.transfercmd (   self,
  cmd,
  rest = None 
) [inherited]
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 
) [inherited]
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) [inherited]
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 657 of file ftplib.py.

ftplib.FTP.af [inherited]

Definition at line 143 of file ftplib.py.

Definition at line 655 of file ftplib.py.

Definition at line 656 of file ftplib.py.

ftplib.FTP.debug = set_debuglevel [static, inherited]

Definition at line 162 of file ftplib.py.

int ftplib.FTP.debugging = 0 [static, inherited]

Definition at line 96 of file ftplib.py.

ftplib.FTP.debugging [inherited]

Definition at line 161 of file ftplib.py.

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

Definition at line 103 of file ftplib.py.

Reimplemented from ftplib.FTP.

Definition at line 679 of file ftplib.py.

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

Definition at line 97 of file ftplib.py.

ftplib.FTP.host [inherited]

Definition at line 137 of file ftplib.py.

Definition at line 654 of file ftplib.py.

ftplib.FTP.lastresp [inherited]

Definition at line 222 of file ftplib.py.

int ftplib.FTP.passiveserver = 1 [static, inherited]

Definition at line 102 of file ftplib.py.

Definition at line 168 of file ftplib.py.

ftplib.FTP.port = FTP_PORT [static, inherited]

Definition at line 98 of file ftplib.py.

Reimplemented from ftplib.FTP.

Definition at line 674 of file ftplib.py.

ftplib.FTP_TLS.ssl_version = ssl.PROTOCOL_TLSv1 [static]

Definition at line 643 of file ftplib.py.

ftplib.FTP.timeout [inherited]

Definition at line 111 of file ftplib.py.

ftplib.FTP.welcome = None [static, inherited]

Definition at line 101 of file ftplib.py.


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