Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v9 / html / python / lib / ftp-objects.html
CommitLineData
920dae64
AT
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<html>
3<head>
4<link rel="STYLESHEET" href="lib.css" type='text/css' />
5<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
6<link rel='start' href='../index.html' title='Python Documentation Index' />
7<link rel="first" href="lib.html" title='Python Library Reference' />
8<link rel='contents' href='contents.html' title="Contents" />
9<link rel='index' href='genindex.html' title='Index' />
10<link rel='last' href='about.html' title='About this document...' />
11<link rel='help' href='about.html' title='About this document...' />
12<link rel="prev" href="module-ftplib.html" />
13<link rel="parent" href="module-ftplib.html" />
14<link rel="next" href="module-gopherlib.html" />
15<meta name='aesop' content='information' />
16<title>11.7.1 FTP Objects </title>
17</head>
18<body>
19<DIV CLASS="navigation">
20<div id='top-navigation-panel' xml:id='top-navigation-panel'>
21<table align="center" width="100%" cellpadding="0" cellspacing="2">
22<tr>
23<td class='online-navigation'><a rel="prev" title="11.7 ftplib "
24 href="module-ftplib.html"><img src='../icons/previous.png'
25 border='0' height='32' alt='Previous Page' width='32' /></A></td>
26<td class='online-navigation'><a rel="parent" title="11.7 ftplib "
27 href="module-ftplib.html"><img src='../icons/up.png'
28 border='0' height='32' alt='Up One Level' width='32' /></A></td>
29<td class='online-navigation'><a rel="next" title="11.8 gopherlib "
30 href="module-gopherlib.html"><img src='../icons/next.png'
31 border='0' height='32' alt='Next Page' width='32' /></A></td>
32<td align="center" width="100%">Python Library Reference</td>
33<td class='online-navigation'><a rel="contents" title="Table of Contents"
34 href="contents.html"><img src='../icons/contents.png'
35 border='0' height='32' alt='Contents' width='32' /></A></td>
36<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
37 border='0' height='32' alt='Module Index' width='32' /></a></td>
38<td class='online-navigation'><a rel="index" title="Index"
39 href="genindex.html"><img src='../icons/index.png'
40 border='0' height='32' alt='Index' width='32' /></A></td>
41</tr></table>
42<div class='online-navigation'>
43<b class="navlabel">Previous:</b>
44<a class="sectref" rel="prev" href="module-ftplib.html">11.7 ftplib </A>
45<b class="navlabel">Up:</b>
46<a class="sectref" rel="parent" href="module-ftplib.html">11.7 ftplib </A>
47<b class="navlabel">Next:</b>
48<a class="sectref" rel="next" href="module-gopherlib.html">11.8 gopherlib </A>
49</div>
50<hr /></div>
51</DIV>
52<!--End of Navigation Panel-->
53
54<H2><A NAME="SECTION0013710000000000000000"></A><A NAME="ftp-objects"></A>
55<BR>
5611.7.1 FTP Objects
57</H2>
58
59<P>
60Several methods are available in two flavors: one for handling text
61files and another for binary files. These are named for the command
62which is used followed by "<tt class="samp">lines</tt>" for the text version or
63"<tt class="samp">binary</tt>" for the binary version.
64
65<P>
66<tt class="class">FTP</tt> instances have the following methods:
67
68<P>
69<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
70 <td><nobr><b><tt id='l2h-3342' xml:id='l2h-3342' class="method">set_debuglevel</tt></b>(</nobr></td>
71 <td><var>level</var>)</td></tr></table></dt>
72<dd>
73Set the instance's debugging level. This controls the amount of
74debugging output printed. The default, <code>0</code>, produces no
75debugging output. A value of <code>1</code> produces a moderate amount of
76debugging output, generally a single line per request. A value of
77<code>2</code> or higher produces the maximum amount of debugging output,
78logging each line sent and received on the control connection.
79</dl>
80
81<P>
82<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
83 <td><nobr><b><tt id='l2h-3343' xml:id='l2h-3343' class="method">connect</tt></b>(</nobr></td>
84 <td><var>host</var><big>[</big><var>, port</var><big>]</big><var></var>)</td></tr></table></dt>
85<dd>
86Connect to the given host and port. The default port number is <code>21</code>, as
87specified by the FTP protocol specification. It is rarely needed to
88specify a different port number. This function should be called only
89once for each instance; it should not be called at all if a host was
90given when the instance was created. All other methods can only be
91used after a connection has been made.
92</dl>
93
94<P>
95<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
96 <td><nobr><b><tt id='l2h-3344' xml:id='l2h-3344' class="method">getwelcome</tt></b>(</nobr></td>
97 <td><var></var>)</td></tr></table></dt>
98<dd>
99Return the welcome message sent by the server in reply to the initial
100connection. (This message sometimes contains disclaimers or help
101information that may be relevant to the user.)
102</dl>
103
104<P>
105<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
106 <td><nobr><b><tt id='l2h-3345' xml:id='l2h-3345' class="method">login</tt></b>(</nobr></td>
107 <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>
108<dd>
109Log in as the given <var>user</var>. The <var>passwd</var> and <var>acct</var>
110parameters are optional and default to the empty string. If no
111<var>user</var> is specified, it defaults to <code>'anonymous'</code>. If
112<var>user</var> is <code>'anonymous'</code>, the default <var>passwd</var> is
113<code>'anonymous@'</code>. This function should be called only
114once for each instance, after a connection has been established; it
115should not be called at all if a host and user were given when the
116instance was created. Most FTP commands are only allowed after the
117client has logged in.
118</dl>
119
120<P>
121<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
122 <td><nobr><b><tt id='l2h-3346' xml:id='l2h-3346' class="method">abort</tt></b>(</nobr></td>
123 <td><var></var>)</td></tr></table></dt>
124<dd>
125Abort a file transfer that is in progress. Using this does not always
126work, but it's worth a try.
127</dl>
128
129<P>
130<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
131 <td><nobr><b><tt id='l2h-3347' xml:id='l2h-3347' class="method">sendcmd</tt></b>(</nobr></td>
132 <td><var>command</var>)</td></tr></table></dt>
133<dd>
134Send a simple command string to the server and return the response
135string.
136</dl>
137
138<P>
139<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
140 <td><nobr><b><tt id='l2h-3348' xml:id='l2h-3348' class="method">voidcmd</tt></b>(</nobr></td>
141 <td><var>command</var>)</td></tr></table></dt>
142<dd>
143Send a simple command string to the server and handle the response.
144Return nothing if a response code in the range 200-299 is received.
145Raise an exception otherwise.
146</dl>
147
148<P>
149<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
150 <td><nobr><b><tt id='l2h-3349' xml:id='l2h-3349' class="method">retrbinary</tt></b>(</nobr></td>
151 <td><var>command,
152 callback</var><big>[</big><var>, maxblocksize</var><big>[</big><var>, rest</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
153<dd>
154Retrieve a file in binary transfer mode. <var>command</var> should be an
155appropriate "<tt class="samp">RETR</tt>" command: <code>'RETR <var>filename</var>'</code>.
156The <var>callback</var> function is called for each block of data received,
157with a single string argument giving the data block.
158The optional <var>maxblocksize</var> argument specifies the maximum chunk size to
159read on the low-level socket object created to do the actual transfer
160(which will also be the largest size of the data blocks passed to
161<var>callback</var>). A reasonable default is chosen. <var>rest</var> means the
162same thing as in the <tt class="method">transfercmd()</tt> method.
163</dl>
164
165<P>
166<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
167 <td><nobr><b><tt id='l2h-3350' xml:id='l2h-3350' class="method">retrlines</tt></b>(</nobr></td>
168 <td><var>command</var><big>[</big><var>, callback</var><big>]</big><var></var>)</td></tr></table></dt>
169<dd>
170Retrieve a file or directory listing in ASCII transfer mode.
171<var>command</var> should be an appropriate "<tt class="samp">RETR</tt>" command (see
172<tt class="method">retrbinary()</tt>) or a "<tt class="samp">LIST</tt>" command (usually just the string
173<code>'LIST'</code>). The <var>callback</var> function is called for each line,
174with the trailing CRLF stripped. The default <var>callback</var> prints
175the line to <code>sys.stdout</code>.
176</dl>
177
178<P>
179<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
180 <td><nobr><b><tt id='l2h-3351' xml:id='l2h-3351' class="method">set_pasv</tt></b>(</nobr></td>
181 <td><var>boolean</var>)</td></tr></table></dt>
182<dd>
183Enable ``passive'' mode if <var>boolean</var> is true, other disable
184passive mode. (In Python 2.0 and before, passive mode was off by
185default; in Python 2.1 and later, it is on by default.)
186</dl>
187
188<P>
189<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
190 <td><nobr><b><tt id='l2h-3352' xml:id='l2h-3352' class="method">storbinary</tt></b>(</nobr></td>
191 <td><var>command, file</var><big>[</big><var>, blocksize</var><big>]</big><var></var>)</td></tr></table></dt>
192<dd>
193Store a file in binary transfer mode. <var>command</var> should be an
194appropriate "<tt class="samp">STOR</tt>" command: <code>"STOR <var>filename</var>"</code>.
195<var>file</var> is an open file object which is read until EOF using its
196<tt class="method">read()</tt> method in blocks of size <var>blocksize</var> to provide the
197data to be stored. The <var>blocksize</var> argument defaults to 8192.
198
199<span class="versionnote">Changed in version 2.1:
200default for <var>blocksize</var> added.</span>
201
202</dl>
203
204<P>
205<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
206 <td><nobr><b><tt id='l2h-3353' xml:id='l2h-3353' class="method">storlines</tt></b>(</nobr></td>
207 <td><var>command, file</var>)</td></tr></table></dt>
208<dd>
209Store a file in ASCII transfer mode. <var>command</var> should be an
210appropriate "<tt class="samp">STOR</tt>" command (see <tt class="method">storbinary()</tt>). Lines are
211read until EOF from the open file object <var>file</var> using its
212<tt class="method">readline()</tt> method to provide the data to be stored.
213</dl>
214
215<P>
216<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
217 <td><nobr><b><tt id='l2h-3354' xml:id='l2h-3354' class="method">transfercmd</tt></b>(</nobr></td>
218 <td><var>cmd</var><big>[</big><var>, rest</var><big>]</big><var></var>)</td></tr></table></dt>
219<dd>
220Initiate a transfer over the data connection. If the transfer is
221active, send a "<tt class="samp">EPRT</tt>" or "<tt class="samp">PORT</tt>" command and the transfer command specified
222by <var>cmd</var>, and accept the connection. If the server is passive,
223send a "<tt class="samp">EPSV</tt>" or "<tt class="samp">PASV</tt>" command, connect to it, and start the transfer
224command. Either way, return the socket for the connection.
225
226<P>
227If optional <var>rest</var> is given, a "<tt class="samp">REST</tt>" command is
228sent to the server, passing <var>rest</var> as an argument. <var>rest</var> is
229usually a byte offset into the requested file, telling the server to
230restart sending the file's bytes at the requested offset, skipping
231over the initial bytes. Note however that RFC
232959 requires only that <var>rest</var> be a string containing characters
233in the printable range from ASCII code 33 to ASCII code 126. The
234<tt class="method">transfercmd()</tt> method, therefore, converts
235<var>rest</var> to a string, but no check is
236performed on the string's contents. If the server does
237not recognize the "<tt class="samp">REST</tt>" command, an
238<tt class="exception">error_reply</tt> exception will be raised. If this happens,
239simply call <tt class="method">transfercmd()</tt> without a <var>rest</var> argument.
240</dl>
241
242<P>
243<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
244 <td><nobr><b><tt id='l2h-3355' xml:id='l2h-3355' class="method">ntransfercmd</tt></b>(</nobr></td>
245 <td><var>cmd</var><big>[</big><var>, rest</var><big>]</big><var></var>)</td></tr></table></dt>
246<dd>
247Like <tt class="method">transfercmd()</tt>, but returns a tuple of the data
248connection and the expected size of the data. If the expected size
249could not be computed, <code>None</code> will be returned as the expected
250size. <var>cmd</var> and <var>rest</var> means the same thing as in
251<tt class="method">transfercmd()</tt>.
252</dl>
253
254<P>
255<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
256 <td><nobr><b><tt id='l2h-3356' xml:id='l2h-3356' class="method">nlst</tt></b>(</nobr></td>
257 <td><var>argument</var><big>[</big><var>, ...</var><big>]</big><var></var>)</td></tr></table></dt>
258<dd>
259Return a list of files as returned by the "<tt class="samp">NLST</tt>" command. The
260optional <var>argument</var> is a directory to list (default is the current
261server directory). Multiple arguments can be used to pass
262non-standard options to the "<tt class="samp">NLST</tt>" command.
263</dl>
264
265<P>
266<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
267 <td><nobr><b><tt id='l2h-3357' xml:id='l2h-3357' class="method">dir</tt></b>(</nobr></td>
268 <td><var>argument</var><big>[</big><var>, ...</var><big>]</big><var></var>)</td></tr></table></dt>
269<dd>
270Produce a directory listing as returned by the "<tt class="samp">LIST</tt>" command,
271printing it to standard output. The optional <var>argument</var> is a
272directory to list (default is the current server directory). Multiple
273arguments 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
274<var>callback</var> function as for <tt class="method">retrlines()</tt>; the default
275prints to <code>sys.stdout</code>. This method returns <code>None</code>.
276</dl>
277
278<P>
279<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
280 <td><nobr><b><tt id='l2h-3358' xml:id='l2h-3358' class="method">rename</tt></b>(</nobr></td>
281 <td><var>fromname, toname</var>)</td></tr></table></dt>
282<dd>
283Rename file <var>fromname</var> on the server to <var>toname</var>.
284</dl>
285
286<P>
287<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
288 <td><nobr><b><tt id='l2h-3359' xml:id='l2h-3359' class="method">delete</tt></b>(</nobr></td>
289 <td><var>filename</var>)</td></tr></table></dt>
290<dd>
291Remove the file named <var>filename</var> from the server. If successful,
292returns the text of the response, otherwise raises
293<tt class="exception">error_perm</tt> on permission errors or
294<tt class="exception">error_reply</tt> on other errors.
295</dl>
296
297<P>
298<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
299 <td><nobr><b><tt id='l2h-3360' xml:id='l2h-3360' class="method">cwd</tt></b>(</nobr></td>
300 <td><var>pathname</var>)</td></tr></table></dt>
301<dd>
302Set the current directory on the server.
303</dl>
304
305<P>
306<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
307 <td><nobr><b><tt id='l2h-3361' xml:id='l2h-3361' class="method">mkd</tt></b>(</nobr></td>
308 <td><var>pathname</var>)</td></tr></table></dt>
309<dd>
310Create a new directory on the server.
311</dl>
312
313<P>
314<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
315 <td><nobr><b><tt id='l2h-3362' xml:id='l2h-3362' class="method">pwd</tt></b>(</nobr></td>
316 <td><var></var>)</td></tr></table></dt>
317<dd>
318Return the pathname of the current directory on the server.
319</dl>
320
321<P>
322<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
323 <td><nobr><b><tt id='l2h-3363' xml:id='l2h-3363' class="method">rmd</tt></b>(</nobr></td>
324 <td><var>dirname</var>)</td></tr></table></dt>
325<dd>
326Remove the directory named <var>dirname</var> on the server.
327</dl>
328
329<P>
330<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
331 <td><nobr><b><tt id='l2h-3364' xml:id='l2h-3364' class="method">size</tt></b>(</nobr></td>
332 <td><var>filename</var>)</td></tr></table></dt>
333<dd>
334Request the size of the file named <var>filename</var> on the server. On
335success, the size of the file is returned as an integer, otherwise
336<code>None</code> is returned. Note that the "<tt class="samp">SIZE</tt>" command is not
337standardized, but is supported by many common server implementations.
338</dl>
339
340<P>
341<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
342 <td><nobr><b><tt id='l2h-3365' xml:id='l2h-3365' class="method">quit</tt></b>(</nobr></td>
343 <td><var></var>)</td></tr></table></dt>
344<dd>
345Send a "<tt class="samp">QUIT</tt>" command to the server and close the connection.
346This is the ``polite'' way to close a connection, but it may raise an
347exception of the server reponds with an error to the
348"<tt class="samp">QUIT</tt>" command. This implies a call to the <tt class="method">close()</tt>
349method which renders the <tt class="class">FTP</tt> instance useless for subsequent
350calls (see below).
351</dl>
352
353<P>
354<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
355 <td><nobr><b><tt id='l2h-3366' xml:id='l2h-3366' class="method">close</tt></b>(</nobr></td>
356 <td><var></var>)</td></tr></table></dt>
357<dd>
358Close the connection unilaterally. This should not be applied to an
359already closed connection such as after a successful call to
360<tt class="method">quit()</tt>. After this call the <tt class="class">FTP</tt> instance should not
361be used any more (after a call to <tt class="method">close()</tt> or
362<tt class="method">quit()</tt> you cannot reopen the connection by issuing another
363<tt class="method">login()</tt> method).
364</dl>
365
366<DIV CLASS="navigation">
367<div class='online-navigation'>
368<p></p><hr />
369<table align="center" width="100%" cellpadding="0" cellspacing="2">
370<tr>
371<td class='online-navigation'><a rel="prev" title="11.7 ftplib "
372 href="module-ftplib.html"><img src='../icons/previous.png'
373 border='0' height='32' alt='Previous Page' width='32' /></A></td>
374<td class='online-navigation'><a rel="parent" title="11.7 ftplib "
375 href="module-ftplib.html"><img src='../icons/up.png'
376 border='0' height='32' alt='Up One Level' width='32' /></A></td>
377<td class='online-navigation'><a rel="next" title="11.8 gopherlib "
378 href="module-gopherlib.html"><img src='../icons/next.png'
379 border='0' height='32' alt='Next Page' width='32' /></A></td>
380<td align="center" width="100%">Python Library Reference</td>
381<td class='online-navigation'><a rel="contents" title="Table of Contents"
382 href="contents.html"><img src='../icons/contents.png'
383 border='0' height='32' alt='Contents' width='32' /></A></td>
384<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
385 border='0' height='32' alt='Module Index' width='32' /></a></td>
386<td class='online-navigation'><a rel="index" title="Index"
387 href="genindex.html"><img src='../icons/index.png'
388 border='0' height='32' alt='Index' width='32' /></A></td>
389</tr></table>
390<div class='online-navigation'>
391<b class="navlabel">Previous:</b>
392<a class="sectref" rel="prev" href="module-ftplib.html">11.7 ftplib </A>
393<b class="navlabel">Up:</b>
394<a class="sectref" rel="parent" href="module-ftplib.html">11.7 ftplib </A>
395<b class="navlabel">Next:</b>
396<a class="sectref" rel="next" href="module-gopherlib.html">11.8 gopherlib </A>
397</div>
398</div>
399<hr />
400<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
401</DIV>
402<!--End of Navigation Panel-->
403<ADDRESS>
404See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
405</ADDRESS>
406</BODY>
407</HTML>