source: release-kits/lirk3/bin/ant-installer/web/manual1.6.2/manual/OptionalTasks/ftp.html@ 14982

Last change on this file since 14982 was 14982, checked in by oranfry, 16 years ago

initial import of LiRK3

File size: 17.8 KB
Line 
1<html>
2
3<head>
4<meta http-equiv="Content-Language" content="en-us">
5<title>FTP Task</title>
6<link rel="stylesheet" type="text/css" href="../stylesheets/antmanual.css">
7</head>
8
9<body>
10
11<h2><a name="ftp">FTP</a></h2>
12<h3>Description</h3>
13<p>The ftp task implements a basic FTP client that can send, receive,
14list, delete files, and create directories. See below for descriptions and examples of how
15to perform each task.</p>
16<p><b>Note:</b> This task depends on external libraries not included in the Ant distribution.
17See <a href="../install.html#commons-net">Library Dependencies</a> for more information.</p>
18<p>The ftp task attempts to determine what file system is in place on the FTP server.
19Supported server types are Unix, NT, OS2, VMS, and OS400. In addition, NT and OS400 servers
20which have been configured to display the directory in Unix style are also supported correctly.
21Otherwise, the system will default to Unix standards.
22<i>remotedir</i> must be specified in the exact syntax required by the ftp
23server. If the usual Unix conventions are not supported by the server,
24<i>separator</i> can be used to set the file separator that should be used
25instead.</p>
26<p>See the section on <a href="../dirtasks.html#directorybasedtasks">directory based
27tasks</a>, on how the inclusion/exclusion of files works, and how to
28write patterns.</p>
29<p>
30This task does not currently use the proxy information set by the
31<a href="setproxy.html">&lt;setproxy&gt;</a> task, and cannot go through
32a firewall via socks.
33<p>
34<b>Warning: </b> there have been problems reported concerning the ftp get with newer attribute.
35Problems might be due to format of ls -l differing from what is expected by commons-net,
36for instance due to specificities of langage used by the ftp server in the directory listing.
37If you encounter such a problem, please send an email including a sample directory listing
38coming from your ftp server (ls -l on the ftp prompt).
39<h3>Parameters</h3>
40<table border="1" cellpadding="2" cellspacing="0">
41 <tr>
42 <td valign="top"><b>Attribute</b></td>
43 <td valign="top"><b>Description</b></td>
44 <td align="center" valign="top"><b>Required</b></td>
45 </tr>
46 <tr>
47 <td valign="top">server</td>
48 <td valign="top">the address of the remote ftp server.</td>
49 <td valign="top" align="center">Yes</td>
50 </tr>
51 <tr>
52 <td valign="top">port</td>
53 <td valign="top">the port number of the remote ftp server.
54 Defaults to port 21.</td>
55 <td valign="top" align="center">No</td>
56 </tr>
57 <tr>
58 <td valign="top">userid</td>
59 <td valign="top">the login id to use on the ftp server.</td>
60 <td valign="top" align="center">Yes</td>
61 </tr>
62 <tr>
63 <td valign="top">password</td>
64 <td valign="top">the login password to use on the ftp server.</td>
65 <td valign="top" align="center">Yes</td>
66 </tr>
67 <tr>
68 <td valign="top">remotedir</td>
69 <td valign="top">remote directory on the
70 ftp server
71 see table below for detailed usage
72 </td>
73 <td valign="top" align="center">No</td>
74 </tr>
75 <tr>
76 <td valign="top">action</td>
77 <td valign="top">the ftp action to perform, defaulting to &quot;send&quot;.
78 Currently supports &quot;put&quot;, &quot;get&quot;,
79 &quot;del&quot;, &quot;list&quot;, &quot;chmod&quot;,
80 &quot;mkdir&quot; and &quot;rmdir&quot;.</td>
81 <td valign="top" align="center">No</td>
82 </tr>
83 <tr>
84 <td valign="top">binary</td>
85 <td valign="top">selects binary-mode (&quot;yes&quot;) or text-mode
86 (&quot;no&quot;) transfers.
87 Defaults to &quot;yes&quot;</td>
88 <td valign="top" align="center">No</td>
89 </tr>
90 <tr>
91 <td valign="top">passive</td>
92 <td valign="top">selects passive-mode (&quot;yes&quot;) transfers.
93 Defaults to &quot;no&quot;</td>
94 <td valign="top" align="center">No</td>
95 </tr>
96 <tr>
97 <td valign="top">verbose</td>
98 <td valign="top">displays information on each file transferred if set
99 to &quot;yes&quot;. Defaults to &quot;no&quot;.</td>
100 <td valign="top" align="center">No</td>
101 </tr>
102 <tr>
103 <td valign="top">depends</td>
104 <td valign="top">transfers only new or changed files if set to
105 &quot;yes&quot;. Defaults to &quot;no&quot;.</td>
106 <td valign="top" align="center">No</td>
107 </tr>
108 <tr>
109 <td valign="top">newer</td>
110 <td valign="top">a synonym for <i>depends</i>.
111 see timediffauto and timediffmillis</td>
112 <td valign="top" align="center">No</td>
113 </tr>
114 <tr>
115 <td valign="top">timediffauto</td>
116 <td valign="top">set to <code>&quot;true&quot;</code>
117 to make ant calculate the time difference between client and server.<br/>
118 <em>requires write access in the remote directory</em><br/>
119 Since ant 1.6</td>
120 <td valign="top" align="center">No</td>
121 </tr>
122 <tr>
123 <td valign="top">timediffmillis</td>
124 <td valign="top">number of milliseconds to add to the time on the remote machine
125 to get the time on the local machine.<br/>
126 Since ant 1.6
127 </td>
128 <td valign="top" align="center">No</td>
129 </tr>
130 <tr>
131 <td valign="top">separator</td>
132 <td valign="top">sets the file separator used on the ftp server.
133 Defaults to &quot;/&quot;.</td>
134 <td valign="top" align="center">No</td>
135 </tr>
136 <tr>
137 <td valign="top">umask</td>
138 <td valign="top">sets the default file permissions for new files,
139 unix only.</td>
140 <td valign="top" align="center">No</td>
141 </tr>
142 <tr>
143 <td valign="top">chmod</td>
144 <td valign="top">sets or changes file permissions for new or existing files,
145 unix only. If used with a put action, chmod will be issued for each file.</td>
146 <td valign="top" align="center">No</td>
147 </tr>
148 <tr>
149 <td valign="top">listing</td>
150 <td valign="top">the file to write results of the &quot;list&quot; action.
151 Required for the &quot;list&quot; action, ignored otherwise.</td>
152 <td valign="top" align="center">No</td>
153 </tr>
154 <tr>
155 <td valign="top">ignoreNoncriticalErrors</td>
156 <td valign="top">flag which permits the task to ignore some non-fatal error
157 codes sent by some servers during directory creation: wu-ftp in particular.
158 Default: false</td>
159 <td valign="top" align="center">No</td>
160 </tr>
161 <tr>
162 <td valign="top">skipFailedTransfers</td>
163 <td valign="top">flag which enables unsuccessful file put, delete
164 and get operations to be skipped with a warning and the
165 remainder of the files still transferred. Default: false</td>
166 <td valign="top" align="center">No</td>
167 </tr>
168 <tr>
169 <td valign="top">preservelastmodified</td>
170 <td valign="top">Give the copied files the same last modified
171 time as the original source files (applies to getting files only).
172 (<em>Note</em>: Ignored on Java 1.1)</td>
173 <td valign="top" align="center">No; defaults to false.</td>
174 </tr>
175</table>
176<h3>Note about remotedir attribute</h3>
177<table border="1" cellpadding="2" cellspacing="0"
178 >
179 <tbody>
180 <tr>
181 <td style="vertical-align: top;" width="20%">Action<br>
182 </td>
183 <td style="vertical-align: top;" width="40%">meaning of <code>remotedir</code><br>
184 </td>
185 <td style="vertical-align: top;">use of nested <code>fileset</code>
186(s)<br>
187 </td>
188 </tr>
189 <tr>
190 <td style="vertical-align: top;" width="20%">send/put<br>
191 </td>
192 <td style="vertical-align: top;" width="40%">base directory to
193which the files are sent<br>
194 </td>
195 <td style="vertical-align: top;">they are used normally and
196evaluated on the local machine<br>
197 </td>
198 </tr>
199 <tr>
200 <td style="vertical-align: top;" width="20%">recv/get<br>
201 </td>
202 <td style="vertical-align: top;" width="40%">base directory from
203which the files are retrieved<br>
204 </td>
205 <td style="vertical-align: top;">the remote files located under
206the <code>remotedir </code>matching the include/exclude patterns of
207the <code>fileset&nbsp;</code></td>
208 </tr>
209 <tr>
210 <td style="vertical-align: top;" width="20%">del/delete<br>
211 </td>
212 <td style="vertical-align: top;" width="40%">base directory from
213which files get deleted<br>
214 </td>
215 <td style="vertical-align: top;">the remote files located under
216the <code>remotedir </code>matching the include/exclude patterns of
217the <code>fileset <br>
218 </code></td>
219 </tr>
220 <tr>
221 <td style="vertical-align: top;" width="20%">list<br>
222 </td>
223 <td style="vertical-align: top;" width="40%">base directory from
224which files are listed<br>
225 </td>
226 <td style="vertical-align: top;">the remote files located under
227the <code>remotedir </code>matching the include/exclude patterns of
228the <code>fileset <br>
229 </code></td>
230 </tr>
231 <tr>
232 <td style="vertical-align: top;" width="20%">mkdir</td>
233 <td style="vertical-align: top;" width="40%">directory to create<br>
234 </td>
235 <td style="vertical-align: top;">not used<br>
236 </td>
237 </tr>
238 <tr>
239 <td style="vertical-align: top;" width="20%">chmod</td>
240 <td style="vertical-align: top;" width="40%">base directory from
241which the mode of files get changed<br>
242 </td>
243 <td style="vertical-align: top;">the remote files located under
244the <code>remotedir </code>matching the include/exclude patterns of
245the <code>fileset <br>
246 </code></td>
247 </tr>
248 <tr>
249 <td style="vertical-align: top;" width="20%">rmdir<br>
250 </td>
251 <td style="vertical-align: top;" width="40%">base directory from
252which directories get removed<br>
253 </td>
254 <td style="vertical-align: top;">the remote directories located
255under the <code>remotedir </code>matching the include/exclude
256patterns of the <code>fileset <br>
257 </code></td>
258 </tr>
259 </tbody>
260</table><h3>Parameters specified as nested elements</h3>
261<h4>fileset</h4>
262<p>The ftp task supports any number of nested <a
263href="../CoreTypes/fileset.html"><code>&lt;fileset&gt;</code></a> elements to specify
264the files to be retrieved, or deleted, or listed, or whose mode you want to change.</p>
265<p>
266The attribute <code>followsymlinks</code> of <code>fileset</code> is fully supported on
267local (put) as well as remote (get, chmod, delete) filesets.
268<em>Before ant 1.6 there was no support of symbolic links in remote filesets.
269In order to exclude symbolic links (preserve the behavior of ant 1.5.x and older),
270you need to explicitly set <code>followsymlinks</code> to <code>false</code>.</em>
271</p>
272<p>
273Remote filesets do not support selectors.<br/>
274</p>
275
276<h3>Sending Files</h3>
277<p>The easiest way to describe how to send files is with a couple of examples:</p>
278<pre>
279 &lt;ftp server=&quot;ftp.apache.org&quot;
280 userid=&quot;anonymous&quot;
281 password=&quot;[email protected]&quot;&gt;
282 &lt;fileset dir=&quot;htdocs/manual&quot;/&gt;
283 &lt;/ftp&gt;
284</pre>
285<p>Logs in to <code>ftp.apache.org</code> as <code>anonymous</code> and
286uploads all files in the <code>htdocs/manual</code> directory
287to the default directory for that user.</p>
288<pre> &lt;ftp server=&quot;ftp.apache.org&quot;
289 remotedir=&quot;incoming&quot;
290 userid=&quot;anonymous&quot;
291 password=&quot;[email protected]&quot;
292 depends=&quot;yes&quot;
293 &gt;
294 &lt;fileset dir=&quot;htdocs/manual&quot;/&gt;
295 &lt;/ftp&gt;</pre>
296<p>Logs in to <code>ftp.apache.org</code> as <code>anonymous</code> and
297uploads all new or changed files in the <code>htdocs/manual</code> directory
298to the <code>incoming</code> directory relative to the default directory
299for <code>anonymous</code>.</p>
300<pre> &lt;ftp server=&quot;ftp.apache.org&quot;
301 port=&quot;2121&quot;
302 remotedir=&quot;/pub/incoming&quot;
303 userid=&quot;coder&quot;
304 password=&quot;java1&quot;
305 depends=&quot;yes&quot;
306 binary=&quot;no&quot;
307 &gt;
308 &lt;fileset dir=&quot;htdocs/manual&quot;&gt;
309 &lt;include name=&quot;**/*.html&quot;/&gt;
310 &lt;/fileset&gt;
311 &lt;/ftp&gt;</pre>
312<p>Logs in to <code>ftp.apache.org</code> at port <code>2121</code> as
313<code>coder</code> with password <code>java1</code> and uploads all new or
314changed HTML files in the <code>htdocs/manual</code> directory to the
315<code>/pub/incoming</code> directory. The files are transferred in text mode. Passive mode has been switched on to send files from behind a firewall.</p>
316<pre> &lt;ftp server=&quot;ftp.nt.org&quot;
317 remotedir=&quot;c:\uploads&quot;
318 userid=&quot;coder&quot;
319 password=&quot;java1&quot;
320 separator=&quot;\&quot;
321 verbose=&quot;yes&quot;</pre>
322<PRE>
323 &gt;
324 &lt;fileset dir=&quot;htdocs/manual&quot;&gt;
325 &lt;include name=&quot;**/*.html&quot;/&gt;
326 &lt;/fileset&gt;
327 &lt;/ftp&gt;</PRE><p>Logs in to the Windows-based <code>ftp.nt.org</code> as
328<code>coder</code> with password <code>java1</code> and uploads all
329HTML files in the <code>htdocs/manual</code> directory to the
330<code>c:\uploads</code> directory. Progress messages are displayed as each
331file is uploaded.</p>
332<h3>Getting Files</h3>
333<p>Getting files from an FTP server works pretty much the same way as
334sending them does. The only difference is that the nested filesets
335use the remotedir attribute as the base directory for the files on the
336FTP server, and the dir attribute as the local directory to put the files
337into. The file structure from the FTP site is preserved on the local machine.</p>
338<pre>
339 &lt;ftp action=&quot;get&quot;
340 server=&quot;ftp.apache.org&quot;
341 userid=&quot;anonymous&quot;
342 password=&quot;[email protected]&quot;&gt;
343 &lt;fileset dir=&quot;htdocs/manual&quot;&gt;
344 &lt;include name=&quot;**/*.html&quot;/&gt;
345 &lt;/fileset&gt;
346 &lt;/ftp&gt;
347</pre>
348<p>Logs in to <code>ftp.apache.org</code> as <code>anonymous</code> and
349recursively downloads all .html files from default directory for that user
350into the <code>htdocs/manual</code> directory on the local machine.</p>
351.
352<h3>Deleting Files</h3>
353As you've probably guessed by now, you use nested fileset elements to
354select the files to delete from the remote FTP server. Again, the
355filesets are relative to the remote directory, not a local directory. In
356fact, the dir attribute of the fileset is ignored completely.
357
358<pre>
359 &lt;ftp action=&quot;del&quot;
360 server=&quot;ftp.apache.org&quot;
361 userid=&quot;anonymous&quot;
362 password=&quot;[email protected]&quot;&gt;
363 &lt;fileset&gt;
364 &lt;include name=&quot;**/*.tmp&quot;/&gt;
365 &lt;/fileset&gt;
366 &lt;/ftp&gt;
367</pre>
368<p>Logs in to <code>ftp.apache.org</code> as <code>anonymous</code> and
369tries to delete all *.tmp files from the default directory for that user.
370If you don't have permission to delete a file, a BuildException is thrown.</p>
371<h3>Listing Files</h3>
372<pre>
373 &lt;ftp action=&quot;list&quot;
374 server=&quot;ftp.apache.org&quot;
375 userid=&quot;anonymous&quot;
376 password=&quot;[email protected]&quot;
377 listing=&quot;data/ftp.listing&quot;&gt;
378 &lt;fileset&gt;
379 &lt;include name=&quot;**&quot;/&gt;
380 &lt;/fileset&gt;
381 &lt;/ftp&gt;
382</pre>
383<p>This provides a file listing in <code>data/ftp.listing</code> of all the files on
384the FTP server relative to the default directory of the <code>anonymous</code>
385user. The listing is in whatever format the FTP server normally lists files.</p>
386
387<h3>Creating Directories</h3>
388<p>Note that with the mkdir action, the directory to create is specified using the
389remotedir attribute.</p>
390<pre>
391 &lt;ftp action=&quot;mkdir&quot;
392 server=&quot;ftp.apache.org&quot;
393 userid=&quot;anonymous&quot;
394 password=&quot;[email protected]&quot;
395 remotedir=&quot;some/remote/dir&quot;/&gt;
396</pre>
397<p>This creates the directory <code>some/remote/dir</code> beneath the default root
398directory. As with all other actions, the directory separator character must be correct
399according to the desires of the FTP server.</p>
400<h3>Removing Directories</h3>
401This action uses nested fileset elements to
402select the directories to remove from the remote FTP server. The
403filesets are relative to the remote directory, not a local directory.
404The dir attribute of the fileset is ignored completely.
405The directories to be removed must be empty, or contain only
406other directories that have been also selected to be removed by the filesets
407patterns, otherwise a BuildException will be thrown.
408Also, if you don't have permission to remove a directory, a BuildException is
409thrown.
410
411<pre>
412 &lt;ftp action=&quot;rmdir&quot;
413 server=&quot;ftp.apache.org&quot;
414 userid=&quot;anonymous&quot;
415 password=&quot;[email protected]&quot;
416 remotedir=&quot;/somedir&quot; &gt;
417 &lt;fileset&gt;
418 &lt;include name=&quot;dira&quot;/&gt;
419 &lt;include name=&quot;dirb/**&quot;/&gt;
420 &lt;/fileset&gt;
421 &lt;/ftp&gt;
422</pre>
423<p>Logs in to <code>ftp.apache.org</code> as <code>anonymous</code> and
424tries to remove <code>/somedir/dira</code> directory and
425all the directories tree starting at, and including, <code>/somedir/dirb</code>.
426When removing the <code>/somedir/dirb</code> tree,
427it will start at the leaves moving up to the root, so that when
428it tries to remove a directory it is sure all the directories under it are
429already removed.
430Obviuosly all the files in the tree must have been already deleted.
431</p>
432<p>As an example suppose you want to delete everything contained into
433<code>/somedir</code>, so invoke first the <code>&lt;ftp&gt;</code> task with
434<code>action=&quot;delete&quot;</code>, then with
435<code>action=&quot;rmdir&quot;</code> specifying in both cases
436<code>remotedir=&quot;/somedir&quot;</code> and
437
438<pre>
439 &lt;fileset&gt;
440 &lt;include name=&quot;**&quot;/&gt;
441 &lt;/fileset&gt;
442</pre>
443
444The directory specified in the <code>remotedir</code> parameter is never
445selected for remove, so if you need to remove it, specify its parent in
446<code>remotedir</code> parameter and include it in the
447<code>&lt;fileset&gt;</code> pattern, like <code>&quot;somedir/**&quot;</code>.
448</p>
449<hr>
450<p align="center">Copyright &copy; 2000-2004 The Apache Software Foundation. All rights
451Reserved.</p>
452
453</body>
454</html>
455
Note: See TracBrowser for help on using the repository browser.