Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v8plus / html / python / lib / ftp-objects.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python Documentation Index' />
<link rel="first" href="lib.html" title='Python Library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="prev" href="module-ftplib.html" />
<link rel="parent" href="module-ftplib.html" />
<link rel="next" href="module-gopherlib.html" />
<meta name='aesop' content='information' />
<title>11.7.1 FTP Objects </title>
</head>
<body>
<DIV CLASS="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="11.7 ftplib "
href="module-ftplib.html"><img src='../icons/previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="11.7 ftplib "
href="module-ftplib.html"><img src='../icons/up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="11.8 gopherlib "
href="module-gopherlib.html"><img src='../icons/next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
href="contents.html"><img src='../icons/contents.png'
border='0' height='32' alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
border='0' height='32' alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
href="genindex.html"><img src='../icons/index.png'
border='0' height='32' alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-ftplib.html">11.7 ftplib </A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-ftplib.html">11.7 ftplib </A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="module-gopherlib.html">11.8 gopherlib </A>
</div>
<hr /></div>
</DIV>
<!--End of Navigation Panel-->
<H2><A NAME="SECTION0013710000000000000000"></A><A NAME="ftp-objects"></A>
<BR>
11.7.1 FTP Objects
</H2>
<P>
Several methods are available in two flavors: one for handling text
files and another for binary files. These are named for the command
which is used followed by "<tt class="samp">lines</tt>" for the text version or
"<tt class="samp">binary</tt>" for the binary version.
<P>
<tt class="class">FTP</tt> instances have the following methods:
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-3342' xml:id='l2h-3342' class="method">set_debuglevel</tt></b>(</nobr></td>
<td><var>level</var>)</td></tr></table></dt>
<dd>
Set the instance's debugging level. This controls the amount of
debugging output printed. The default, <code>0</code>, produces no
debugging output. A value of <code>1</code> produces a moderate amount of
debugging output, generally a single line per request. A value of
<code>2</code> or higher produces the maximum amount of debugging output,
logging each line sent and received on the control connection.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-3343' xml:id='l2h-3343' class="method">connect</tt></b>(</nobr></td>
<td><var>host</var><big>[</big><var>, port</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Connect to the given host and port. The default port number is <code>21</code>, as
specified by the FTP protocol specification. It is rarely needed to
specify a different port number. This function should be called only
once for each instance; it should not be called at all if a host was
given when the instance was created. All other methods can only be
used after a connection has been made.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-3344' xml:id='l2h-3344' class="method">getwelcome</tt></b>(</nobr></td>
<td><var></var>)</td></tr></table></dt>
<dd>
Return the welcome message sent by the server in reply to the initial
connection. (This message sometimes contains disclaimers or help
information that may be relevant to the user.)
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-3345' xml:id='l2h-3345' class="method">login</tt></b>(</nobr></td>
<td><var></var><big>[</big><var>user</var><big>[</big><var>, passwd</var><big>[</big><var>, acct</var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Log in as the given <var>user</var>. The <var>passwd</var> and <var>acct</var>
parameters are optional and default to the empty string. If no
<var>user</var> is specified, it defaults to <code>'anonymous'</code>. If
<var>user</var> is <code>'anonymous'</code>, the default <var>passwd</var> is
<code>'anonymous@'</code>. This function should be called only
once for each instance, after a connection has been established; it
should not be called at all if a host and user were given when the
instance was created. Most FTP commands are only allowed after the
client has logged in.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-3346' xml:id='l2h-3346' class="method">abort</tt></b>(</nobr></td>
<td><var></var>)</td></tr></table></dt>
<dd>
Abort a file transfer that is in progress. Using this does not always
work, but it's worth a try.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-3347' xml:id='l2h-3347' class="method">sendcmd</tt></b>(</nobr></td>
<td><var>command</var>)</td></tr></table></dt>
<dd>
Send a simple command string to the server and return the response
string.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-3348' xml:id='l2h-3348' class="method">voidcmd</tt></b>(</nobr></td>
<td><var>command</var>)</td></tr></table></dt>
<dd>
Send a simple command string to the server and handle the response.
Return nothing if a response code in the range 200-299 is received.
Raise an exception otherwise.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-3349' xml:id='l2h-3349' class="method">retrbinary</tt></b>(</nobr></td>
<td><var>command,
callback</var><big>[</big><var>, maxblocksize</var><big>[</big><var>, rest</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Retrieve a file in binary transfer mode. <var>command</var> should be an
appropriate "<tt class="samp">RETR</tt>" command: <code>'RETR <var>filename</var>'</code>.
The <var>callback</var> function is called for each block of data received,
with a single string argument giving the data block.
The optional <var>maxblocksize</var> argument specifies the maximum chunk size to
read on the low-level socket object created to do the actual transfer
(which will also be the largest size of the data blocks passed to
<var>callback</var>). A reasonable default is chosen. <var>rest</var> means the
same thing as in the <tt class="method">transfercmd()</tt> method.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-3350' xml:id='l2h-3350' class="method">retrlines</tt></b>(</nobr></td>
<td><var>command</var><big>[</big><var>, callback</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Retrieve a file or directory listing in ASCII transfer mode.
<var>command</var> should be an appropriate "<tt class="samp">RETR</tt>" command (see
<tt class="method">retrbinary()</tt>) or a "<tt class="samp">LIST</tt>" command (usually just the string
<code>'LIST'</code>). The <var>callback</var> function is called for each line,
with the trailing CRLF stripped. The default <var>callback</var> prints
the line to <code>sys.stdout</code>.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-3351' xml:id='l2h-3351' class="method">set_pasv</tt></b>(</nobr></td>
<td><var>boolean</var>)</td></tr></table></dt>
<dd>
Enable ``passive'' mode if <var>boolean</var> is true, other disable
passive mode. (In Python 2.0 and before, passive mode was off by
default; in Python 2.1 and later, it is on by default.)
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-3352' xml:id='l2h-3352' class="method">storbinary</tt></b>(</nobr></td>
<td><var>command, file</var><big>[</big><var>, blocksize</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Store a file in binary transfer mode. <var>command</var> should be an
appropriate "<tt class="samp">STOR</tt>" command: <code>"STOR <var>filename</var>"</code>.
<var>file</var> is an open file object which is read until EOF using its
<tt class="method">read()</tt> method in blocks of size <var>blocksize</var> to provide the
data to be stored. The <var>blocksize</var> argument defaults to 8192.
<span class="versionnote">Changed in version 2.1:
default for <var>blocksize</var> added.</span>
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-3353' xml:id='l2h-3353' class="method">storlines</tt></b>(</nobr></td>
<td><var>command, file</var>)</td></tr></table></dt>
<dd>
Store a file in ASCII transfer mode. <var>command</var> should be an
appropriate "<tt class="samp">STOR</tt>" command (see <tt class="method">storbinary()</tt>). Lines are
read until EOF from the open file object <var>file</var> using its
<tt class="method">readline()</tt> method to provide the data to be stored.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-3354' xml:id='l2h-3354' class="method">transfercmd</tt></b>(</nobr></td>
<td><var>cmd</var><big>[</big><var>, rest</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Initiate a transfer over the data connection. If the transfer is
active, send a "<tt class="samp">EPRT</tt>" or "<tt class="samp">PORT</tt>" command and the transfer command specified
by <var>cmd</var>, and accept the connection. If the server is passive,
send a "<tt class="samp">EPSV</tt>" or "<tt class="samp">PASV</tt>" command, connect to it, and start the transfer
command. Either way, return the socket for the connection.
<P>
If optional <var>rest</var> is given, a "<tt class="samp">REST</tt>" command is
sent to the server, passing <var>rest</var> as an argument. <var>rest</var> is
usually a byte offset into the requested file, telling the server to
restart sending the file's bytes at the requested offset, skipping
over the initial bytes. Note however that RFC
959 requires only that <var>rest</var> be a string containing characters
in the printable range from ASCII code 33 to ASCII code 126. The
<tt class="method">transfercmd()</tt> method, therefore, converts
<var>rest</var> to a string, but no check is
performed on the string's contents. If the server does
not recognize the "<tt class="samp">REST</tt>" command, an
<tt class="exception">error_reply</tt> exception will be raised. If this happens,
simply call <tt class="method">transfercmd()</tt> without a <var>rest</var> argument.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-3355' xml:id='l2h-3355' class="method">ntransfercmd</tt></b>(</nobr></td>
<td><var>cmd</var><big>[</big><var>, rest</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Like <tt class="method">transfercmd()</tt>, but returns a tuple of the data
connection and the expected size of the data. If the expected size
could not be computed, <code>None</code> will be returned as the expected
size. <var>cmd</var> and <var>rest</var> means the same thing as in
<tt class="method">transfercmd()</tt>.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-3356' xml:id='l2h-3356' class="method">nlst</tt></b>(</nobr></td>
<td><var>argument</var><big>[</big><var>, ...</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Return a list of files as returned by the "<tt class="samp">NLST</tt>" command. The
optional <var>argument</var> is a directory to list (default is the current
server directory). Multiple arguments can be used to pass
non-standard options to the "<tt class="samp">NLST</tt>" command.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-3357' xml:id='l2h-3357' class="method">dir</tt></b>(</nobr></td>
<td><var>argument</var><big>[</big><var>, ...</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Produce a directory listing as returned by the "<tt class="samp">LIST</tt>" command,
printing it to standard output. The optional <var>argument</var> is a
directory to list (default is the current server directory). Multiple
arguments can be used to pass non-standard options to the "<tt class="samp">LIST</tt>"command. If the last argument is a function, it is used as a
<var>callback</var> function as for <tt class="method">retrlines()</tt>; the default
prints to <code>sys.stdout</code>. This method returns <code>None</code>.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-3358' xml:id='l2h-3358' class="method">rename</tt></b>(</nobr></td>
<td><var>fromname, toname</var>)</td></tr></table></dt>
<dd>
Rename file <var>fromname</var> on the server to <var>toname</var>.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-3359' xml:id='l2h-3359' class="method">delete</tt></b>(</nobr></td>
<td><var>filename</var>)</td></tr></table></dt>
<dd>
Remove the file named <var>filename</var> from the server. If successful,
returns the text of the response, otherwise raises
<tt class="exception">error_perm</tt> on permission errors or
<tt class="exception">error_reply</tt> on other errors.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-3360' xml:id='l2h-3360' class="method">cwd</tt></b>(</nobr></td>
<td><var>pathname</var>)</td></tr></table></dt>
<dd>
Set the current directory on the server.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-3361' xml:id='l2h-3361' class="method">mkd</tt></b>(</nobr></td>
<td><var>pathname</var>)</td></tr></table></dt>
<dd>
Create a new directory on the server.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-3362' xml:id='l2h-3362' class="method">pwd</tt></b>(</nobr></td>
<td><var></var>)</td></tr></table></dt>
<dd>
Return the pathname of the current directory on the server.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-3363' xml:id='l2h-3363' class="method">rmd</tt></b>(</nobr></td>
<td><var>dirname</var>)</td></tr></table></dt>
<dd>
Remove the directory named <var>dirname</var> on the server.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-3364' xml:id='l2h-3364' class="method">size</tt></b>(</nobr></td>
<td><var>filename</var>)</td></tr></table></dt>
<dd>
Request the size of the file named <var>filename</var> on the server. On
success, the size of the file is returned as an integer, otherwise
<code>None</code> is returned. Note that the "<tt class="samp">SIZE</tt>" command is not
standardized, but is supported by many common server implementations.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-3365' xml:id='l2h-3365' class="method">quit</tt></b>(</nobr></td>
<td><var></var>)</td></tr></table></dt>
<dd>
Send a "<tt class="samp">QUIT</tt>" command to the server and close the connection.
This is the ``polite'' way to close a connection, but it may raise an
exception of the server reponds with an error to the
"<tt class="samp">QUIT</tt>" command. This implies a call to the <tt class="method">close()</tt>
method which renders the <tt class="class">FTP</tt> instance useless for subsequent
calls (see below).
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-3366' xml:id='l2h-3366' class="method">close</tt></b>(</nobr></td>
<td><var></var>)</td></tr></table></dt>
<dd>
Close the connection unilaterally. This should not be applied to an
already closed connection such as after a successful call to
<tt class="method">quit()</tt>. After this call the <tt class="class">FTP</tt> instance should not
be used any more (after a call to <tt class="method">close()</tt> or
<tt class="method">quit()</tt> you cannot reopen the connection by issuing another
<tt class="method">login()</tt> method).
</dl>
<DIV CLASS="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="11.7 ftplib "
href="module-ftplib.html"><img src='../icons/previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="11.7 ftplib "
href="module-ftplib.html"><img src='../icons/up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="11.8 gopherlib "
href="module-gopherlib.html"><img src='../icons/next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
href="contents.html"><img src='../icons/contents.png'
border='0' height='32' alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
border='0' height='32' alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
href="genindex.html"><img src='../icons/index.png'
border='0' height='32' alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-ftplib.html">11.7 ftplib </A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-ftplib.html">11.7 ftplib </A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="module-gopherlib.html">11.8 gopherlib </A>
</div>
</div>
<hr />
<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>