summaryrefslogtreecommitdiff
path: root/manual/Tasks/ftp.html
blob: 0ded19d2fb60687b559fc63b57f64bce360d6768 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
<!--
   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for additional information regarding copyright ownership.
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
-->
<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
<title>FTP Task</title>
</head>

<body>

<h2 id="ftp">FTP</h2>
<h3>Description</h3>
<p>The <code>ftp</code> task implements a basic FTP client that can send, receive, list, delete
files, and create directories.  See below for descriptions and examples of how to perform each
task.</p>
<p><strong>Note</strong>: This task depends on external libraries not included in the Apache Ant
distribution.  See <a href="../install.html#commons-net">Library Dependencies</a> for more
information. <em>Get the latest version of this library, for the best support in Ant.</em></p>
<p>The <code>ftp</code> task attempts to determine what file system is in place on the FTP server.
Supported server types are Unix, NT, OS2, VMS, and OS400.  In addition, NT and OS400 servers which
have been configured to display the directory in Unix style are also supported correctly.
Otherwise, the system will default to Unix standards. <var>remotedir</var> must be specified in the
exact syntax required by the FTP server. If the usual Unix conventions are not supported by the
server, <var>separator</var> can be used to set the file separator that should be used instead.</p>
<p>See the section on <a href="../dirtasks.html#directorybasedtasks">directory based tasks</a>, on
how the inclusion/exclusion of files works, and how to write patterns.</p>
<p>This task does not currently use the proxy information set by
the <a href="setproxy.html"><code>&lt;setproxy&gt;</code></a> task, and cannot go through a firewall
via socks.</p>
<p><strong>Warning</strong>: there have been problems reported concerning
the <code>ftp</code> <q>get</q> with the <var>newer</var> attribute.  Problems might be due to
format of <code>ls -l</code> differing from what is expected by commons-net, for instance due to
specifics of language used by the FTP server in the directory listing.  If you encounter such a
problem, please send an email including a sample directory listing coming from your FTP server
(<code>ls -l</code> on the FTP prompt).</p>
<p>If you can connect but not upload or download, try setting the <var>passive</var> attribute
to <q>true</q> to use the existing (open) channel, instead of having the server try to set up a new
connection.</p>

<h3>Parameters</h3>
<table class="attr">
  <tr>
    <th>Attribute</th>
    <th>Description</th>
    <th>Required</th>
  </tr>
  <tr>
    <td>server</td>
    <td>the address of the remote FTP server.</td>
    <td>Yes</td>
  </tr>
  <tr>
    <td>port</td>
    <td>the port number of the remote FTP server.</td>
    <td>No; defaults to <q>21</q></td>
  </tr>
  <tr>
    <td>userid</td>
    <td>the login id to use on the FTP server.</td>
    <td>Yes</td>
  </tr>
  <tr>
    <td>password</td>
    <td>the login password to use on the FTP server.</td>
    <td>Yes</td>
  </tr>
  <tr>
    <td>account</td>
    <td>the account to use on the FTP server.
    <em>since Ant 1.7</em>.</td>
    <td>No</td>
  </tr>
  <tr>
    <td>remotedir</td>
    <td>remote directory on the FTP server see table below for detailed usage</td>
    <td>No</td>
  </tr>
  <tr>
    <td>action</td>
    <td>FTP action to perform.  Currently
    supports <q>put</q>, <q>get</q>, <q>del</q>, <q>list</q>, <q>chmod</q>, <q>mkdir</q>, <q>rmdir</q>,
    and <q>site</q>.</td>
    <td>No; defaults to <q>send</q></td>
  </tr>
  <tr>
    <td>binary</td>
    <td>selects binary-mode (<q>yes</q>) or text-mode (<q>no</q>) transfers.</td>
    <td>No; defaults to <q>yes</q></td>
  </tr>
  <tr>
    <td>passive</td>
    <td>selects passive-mode (<q>yes</q>) transfers, for better through-firewall connectivity, at
      the price of performance.</td>
    <td>No; defaults to <q>no</q></td>
  </tr>
  <tr>
    <td>verbose</td>
    <td>displays information on each file transferred if set to <q>yes</q>.</td>
    <td>No; defaults to <q>no</q></td>
  </tr>
  <tr>
    <td>depends</td>
    <td>transfers only new or changed files if set to <q>yes</q>.</td>
    <td>No; defaults to <q>no</q></td>
  </tr>
  <tr>
    <td>newer</td>
    <td>a synonym for <var>depends</var>.  See <var>timediffauto</var>
        and <var>timediffmillis</var></td>
    <td>No</td>
  </tr>
  <tr>
    <td>timediffauto</td>
    <td>set to <q>true</q> to make Ant calculate the time difference between client and
    server.<br/><em>requires write access in the remote directory</em><br/><em>Since Ant
    1.6</em></td>
    <td>No</td>
  </tr>
  <tr id="timestampGranularity">
    <td>timestampGranularity</td>
    <td>Specify either <q>MINUTE</q>, <q>NONE</q>, (or you may specify <q></q> which is equivalent
      to not specifying a value, useful for property-file driven scripts).  Allows override of the
      typical situation in <q>PUT</q> and <q>GET</q> where local filesystem timestamps
      are <code>HH:mm:ss</code> and the typical FTP server's timestamps are <code>HH:mm</code>.
      This can throw off <var>uptodate</var> calculations.  However, the default values should
      suffice for most applications.<br/><em>Since Ant 1.7</em></td>
    <td>No; only applies in <q>put</q> and <q>get</q> where the default values are <q>MINUTE</q>
      for <code>PUT</code> and <q>NONE</q> for <code>GET</code>.  (It is not as necessary
      in <q>get</q> because we have the <var>preservelastmodified</var> option.)</td>
  </tr>
  <tr>
    <td>timediffmillis</td>
    <td><em><u>Deprecated</u></em>. Number of milliseconds to add to the time on the remote machine
      to get the time on the local machine.  The <var>timestampGranularity</var> attribute (for
      which the default values should suffice in most situations), and
      the <var>serverTimeZoneConfig</var> option, should make this
      unnecessary.  <var>serverTimeZoneConfig</var> does the math for you and also knows about
      Daylight Savings Time.<br/><em>Since Ant 1.6</em></td>
    <td>No</td>
  </tr>
  <tr>
    <td>separator</td>
    <td>sets the file separator used on the FTP server.</td>
    <td>No; defaults to <q>/</q></td>
  </tr>
  <tr>
    <td>umask</td>
    <td>sets the default file permissions for new files, Unix only.</td>
    <td>No</td>
  </tr>
  <tr>
    <td>chmod</td>
    <td>sets or changes file permissions for new or existing files, Unix only. If used with
      a <q>put</q> action, <code>chmod</code> will be issued for each file.</td>
    <td>No</td>
  </tr>
  <tr>
    <td>listing</td>
    <td>the file to write results of the <q>list</q> action.  Required for the <q>list</q> action,
      ignored otherwise.</td>
    <td>No</td>
  </tr>
  <tr>
    <td>ignoreNoncriticalErrors</td>
    <td>flag which permits the task to ignore some non-fatal error codes sent by some servers during
      directory creation: wu-ftp in particular.</td>
    <td>No; defaults to <q>false</q></td>
  </tr>
  <tr>
    <td>skipFailedTransfers</td>
    <td>flag which enables unsuccessful file <q>put</q>, <q>delete</q> and <q>get</q> operations to
      be skipped with a warning and the remainder of the files still transferred.</td>
    <td>No; default to <q>false</q></td>
  </tr>
  <tr>
    <td>preservelastmodified</td>
    <td>Give the copied files the same last modified time as the original source files (applies to
      getting files only).  (<strong>Note</strong>: Ignored on Java 1.1)</td>
    <td>No; defaults to <q>false</q></td>
  </tr>
  <tr>
    <td>retriesAllowed</td>
    <td>Set the number of retries allowed on an file-transfer operation.  If a positive number is
      specified, each file transfer can fail up to that many times before the operation is failed.
      If <q>-1</q> or <q>forever</q> specified, the operation will keep trying until it
      succeeds.</td>
    <td>No; defaults to <q>0</q></td>
  </tr>
  <tr>
    <td>siteCommand</td>
    <td>Set the server-specific <code>SITE</code> command to execute if the <var>action</var>
      attribute has been specified as <q>site</q>.
    <td>No</td>
  </tr>
  <tr>
    <td>initialSiteCommand</td>
    <td>Set a server-specific <code>SITE</code> command to execute immediately after login.</td>
    <td>No</td>
  </tr>
  <tr>
    <td>enableRemoteVerification</td>
    <td>Whether data connection should be verified to connect to the same host as the control
      connection.  This is a security measure that is enabled by default, but it may be useful to
      disable it in certain firewall scenarios.  <em>since Ant 1.8.0</em></td>
    <td>No; default is <q>true</q></td>
  </tr>
  <tr>
    <td colspan="3" class="left">
      <p><strong>The following attributes
      require <a href="https://commons.apache.org/net/download_net.cgi">jakarta-commons-net-1.4.0 or
      greater</a>.</strong></p>
      <p>Use these options when the standard options don't work, because</p>
      <ul>
        <li>the server is in a different timezone and you need timestamp dependency checking</li>
        <li>the default timestamp formatting doesn't match the server display and list parsing
          therefore fails</li>
      </ul>
      <p>If none of these is specified, the default mechanism of letting the system auto-detect the
      server OS type based on the FTP <code>SYST</code> command and assuming standard formatting
      for that OS type will be used.</p>
      <p>To aid in property-file-based development where a build script is configured with property
      files, for any of these attributes, a value of <q></q> is equivalent to not specifying it.</p>
      <p>Please understand that these options are incompatible with the autodetection scheme.  If
      any of these options is specified, (other than with a value of <q></q>) a system type must be
      chosen and if <var>systemTypeKey</var> is not specified, UNIX will be assumed. The philosophy
      behind this is that these options are for setting non-standard formats, and a build-script
      author who knows what system he is dealing with will know what options to need to be
      set. Otherwise, these options should be left alone and the default autodetection scheme can be
      used and will work in the majority of cases.</p>
    </td>
  </tr>
  <tr>
    <td>systemTypeKey</td>
    <td>Specifies the type of system in use on the server.  Supported values
      are <q>UNIX</q>, <q>VMS</q>, <q>WINDOWS</q>, <q>OS/2</q>, <q>OS/400</q>, <q>MVS</q>. If not
      specified, (or specified as <q></q>) and if no other <var>xxxConfig</var> attributes are
      specified, the autodetection mechanism based on the FTP <code>SYST</code> command will be
      used.<br/><em>Since Ant 1.7</em></td>
    <td>No, but if any of the following <var>xxxConfig</var> attributes is specified, UNIX will be
      assumed, even if <q></q> is specified here.
    </td>
  </tr>
  <tr>
    <td>serverTimeZoneConfig</td>
    <td>Specify as a
      Java <a href="https://docs.oracle.com/javase/8/docs/api/java/util/TimeZone.html">TimeZone</a>
      identifier, (e.g. <q>GMT</q>, <q>America/Chicago</q> or <q>Asia/Jakarta</q>) the timezone used
      by the server for timestamps.  This enables timestamp dependency checking even when the server
      is in a different time zone from the client. Time Zones know, also, about daylight savings
      time, and do not require you to calculate milliseconds of difference.  If not specified, (or
      specified as <q></q>), the time zone of the client is assumed.<br/><em>Since Ant 1.7</em></td>
    <td>No</td>
  </tr>
  <tr>
    <td>defaultDateFormatConfig</td>
    <td>Specify in
      Java <a href="https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html">SimpleDateFormat</a>
      notation, (e.g. <q>yyyy-MM-dd</q>), the date format generally used by the FTP server to parse
      dates.  In some cases this will be the only date format used.  In others, (<q>unix</q> for
      example) this will be used for dates older than a year
      old. (See <var>recentDateFormatConfig</var>).  When specified as <q></q>, default value will
      be used.<br/><em>Since Ant 1.7</em></td>
    <td>No; defaults to default date format for the system type indicated
      by <var>systemTypeKey</var></td>
  </tr>
  <tr>
    <td>recentDateFormatConfig</td>
    <td>Specify in
      Java <a href="https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html">SimpleDateFormat</a>
      notation, (e.g. <q>MMM dd hh:mm</q>) the date format used by the FTP server to parse dates
      less than a year old.  If not specified (or specified as <q></q>), and if the system type
      indicated by the <var>systemTypeKey</var> uses a recent date format, its standard format will
      be used.<br/><em>Since Ant 1.7</em></td>
    <td>No</td>
  </tr>
  <tr>
    <td>serverLanguageCodeConfig</td>
    <td>a <a href="http://www.mathguide.de/info/tools/languagecode.html">two-letter ISO-639 language
      code</a> used to specify the language used by the server to format month names.  This only
      needs to be specified when the server uses non-numeric abbreviations for months in its date
      listings in a language other than English.  This appears to be becoming rarer and rarer, as
      commonly distributed FTP servers seem increasingly to use English or all-numeric formats.
      Languages supported are:
      <ul>
        <li><q>en</q>&mdash;English</li>
        <li><q>fr</q>&mdash;French</li>
        <li><q>de</q>&mdash;German</li>
        <li><q>it</q>&mdash;Italian</li>
        <li><q>es</q>&mdash;Spanish</li>
        <li><q>pt</q>&mdash;Portuguese</li>
        <li><q>da</q>&mdash;Danish</li>
        <li><q>sv</q>&mdash;Swedish</li>
        <li><q>no</q>&mdash;Norwegian</li>
        <li><q>nl</q>&mdash;Dutch</li>
        <li><q>ro</q>&mdash;Romanian</li>
        <li><q>sq</q>&mdash;Albanian</li>
        <li><q>sh</q>&mdash;Serbo-Croatian</li>
        <li><q>sk</q>&mdash;Slovak</li>
        <li><q>sl</q>&mdash;Slovenian</li>
      </ul>
      If you require a language other than the above, see also the <var>shortMonthNamesConfig</var>
      attribute.<br/><em>Since Ant 1.7</em></td>
    <td>No</td>
  </tr>
  <tr>
    <td>shortMonthNamesConfig</td>
    <td>specify the month abbreviations used on the server in file timestamp dates as a
      pipe-delimited string for each month. For example, a set of month names used by a hypothetical
      Icelandic FTP server might conceivably be specified
      as <q>jan|feb|mar|apr|ma&iacute;|j&uacute;n|j&uacute;l|&aacute;g&uacute;|sep|okt|n&oacute;v|des</q>.
      This attribute exists primarily to support languages not supported by
      the <var>serverLanguageCode</var> attribute.<br/><em>Since Ant 1.7</em></td>
    <td>No</td>
  </tr>
</table>
<h3>Note about <var>remotedir</var> attribute</h3>
<table>
  <thead>
    <tr>
      <th>Action</th>
      <th>meaning of <var>remotedir</var></th>
      <th>use of nested <var>fileset</var>(s)</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><q>send</q>/<q>put</q></td>
      <td>base directory to which the files are sent</td>
      <td>they are used normally and evaluated on the local machine</td>
    </tr>
    <tr>
      <td><q>recv</q>/<q>get</q></td>
      <td>base directory from which the files are retrieved</td>
      <td>the remote files located under the <var>remotedir</var> matching the include/exclude
        patterns of the <var>fileset</var></td>
    </tr>
    <tr>
      <td><q>del</q>/<q>delete</q></td>
      <td>base directory from which files get deleted</td>
      <td>the remote files located under the <var>remotedir</var> matching the include/exclude
        patterns of the <var>fileset</var></td>
    </tr>
    <tr>
      <td><q>list</q></td>
      <td>base directory from which files are listed</td>
      <td>the remote files located under the <var>remotedir</var> matching the include/exclude
        patterns of the <var>fileset</var></td>
    </tr>
    <tr>
      <td><q>mkdir</q></td>
      <td>directory to create</td>
      <td><em>not used</em></td>
    </tr>
    <tr>
      <td><q>chmod</q></td>
      <td>base directory from which the mode of files get changed</td>
      <td>the remote files located under the <var>remotedir</var> matching the include/exclude
        patterns of the <var>fileset</var></td>
    </tr>
    <tr>
      <td><q>rmdir</q></td>
      <td>base directory from which directories get removed</td>
      <td>the remote directories located under the <var>remotedir</var> matching the include/exclude
        patterns of the <var>fileset</var></td>
    </tr>
  </tbody>
</table>
<h3>Parameters specified as nested elements</h3>
<h4>fileset</h4>
<p>The <code>ftp</code> task supports any number of
nested <a href="../Types/fileset.html"><code>&lt;fileset&gt;</code></a> elements to specify the
files to be retrieved, or deleted, or listed, or whose mode you want to change.</p>
<p>The attribute <var>followsymlinks</var> of <code>fileset</code> is supported on local
(<q>put</q>) as well as remote (<q>get</q>, <q>chmod</q>, <q>delete</q>) filesets.  <em>Before Ant
1.6 there was no support of symbolic links in remote filesets.  In order to exclude symbolic links
(preserve the behavior of Ant 1.5.x and older), you need to explicitly set <var>followsymlinks</var>
to <q>false</q>.</em>  On remote filesets hidden files are not checked for being symbolic links.
Hidden files are currently assumed to not be symbolic links.</p>

<h3>Sending files</h3>
<p>The easiest way to describe how to send files is with a couple of examples:</p>
<pre>
&lt;ftp server="ftp.apache.org"
     userid="anonymous"
     password="me@myorg.com"&gt;
    &lt;fileset dir="htdocs/manual"/&gt;
&lt;/ftp&gt;</pre>
<p>Logs in to <samp>ftp.apache.org</samp> as <samp>anonymous</samp> and uploads all files in
the <samp>htdocs/manual</samp> directory to the default directory for that user.</p>
<pre>
&lt;ftp server="ftp.apache.org"
     remotedir="incoming"
     userid="anonymous"
     password="me@myorg.com"
     depends="yes"&gt;
    &lt;fileset dir="htdocs/manual"/&gt;
&lt;/ftp&gt;</pre>
<p>Logs in to <samp>ftp.apache.org</samp> as <samp>anonymous</samp> and uploads all new or changed
files in the <samp>htdocs/manual</samp> directory to the <samp>incoming</samp> directory relative to
the default directory for <samp>anonymous</samp>.</p>
<pre>
&lt;ftp server="ftp.apache.org"
     port="2121"
     remotedir="/pub/incoming"
     userid="coder"
     password="java1"
     passive="yes"
     depends="yes"
     binary="no"&gt;
    &lt;fileset dir="htdocs/manual"&gt;
        &lt;include name="**/*.html"/&gt;
    &lt;/fileset&gt;
&lt;/ftp&gt;</pre>
<p>Logs in to <samp>ftp.apache.org</samp> at port <samp>2121</samp> as <samp>coder</samp> with
password <samp>java1</samp> and uploads all new or changed HTML files in
the <samp>htdocs/manual</samp> directory to the <samp>/pub/incoming</samp> directory. The files are
transferred in text mode.  Passive mode has been switched on to send files from behind a
firewall.</p>
<pre>
&lt;ftp server="ftp.hypothetical.india.org"
     port="2121"
     remotedir="/pub/incoming"
     userid="coder"
     password="java1"
     depends="yes"
     binary="no"
     systemTypeKey="Windows"
     serverTimeZoneConfig="India/Calcutta"&gt;
    &lt;fileset dir="htdocs/manual"&gt;
        &lt;include name="**/*.html"/&gt;
    &lt;/fileset&gt;
&lt;/ftp&gt;</pre>
<p>Logs in to a Windows server at <samp>ftp.hypothetical.india.org</samp> at port <samp>2121</samp>
as <samp>coder</samp> with password <samp>java1</samp> and uploads all new or changed (accounting
for timezone differences) HTML files in the <samp>htdocs/manual</samp> directory to
the <samp>/pub/incoming</samp> directory. The files are transferred in text mode.</p>
<pre>
&lt;ftp server="ftp.nt.org"
     remotedir="c:\uploads"
     userid="coder"
     password="java1"
     separator="\"
     verbose="yes"&gt;
    &lt;fileset dir="htdocs/manual"&gt;
        &lt;include name="**/*.html"/&gt;
    &lt;/fileset&gt;
&lt;/ftp&gt;</pre>
<p>Logs in to the Windows-based <samp>ftp.nt.org</samp> as <samp>coder</samp> with
password <samp>java1</samp> and uploads all HTML files in the <samp>htdocs/manual</samp> directory
to the <samp>c:\uploads</samp> directory.  Progress messages are displayed as each file is
uploaded.</p>
<h3>Getting files</h3>
<p>Getting files from an FTP server works pretty much the same way as sending them does.  The only
difference is that the nested filesets use the <var>remotedir</var> attribute as the base directory
for the files on the FTP server, and the <var>dir</var> attribute as the local directory to put the
files into.  The file structure from the FTP site is preserved on the local machine.</p>
<pre>
&lt;ftp action="get"
     server="ftp.apache.org"
     userid="anonymous"
     password="me@myorg.com"&gt;
    &lt;fileset dir="htdocs/manual"&gt;
        &lt;include name="**/*.html"/&gt;
    &lt;/fileset&gt;
&lt;/ftp&gt;</pre>
<p>Logs in to <samp>ftp.apache.org</samp> as <samp>anonymous</samp> and recursively downloads
all <samp>.html</samp> files from default directory for that user into
the <samp>htdocs/manual</samp> directory on the local machine.</p>
<pre>
&lt;ftp action="get"
     server="ftp.apache.org"
     userid="anonymous"
     password="me@myorg.com"
     systemTypeKey="UNIX"
     defaultDateFormatConfig="yyyy-MM-dd HH:mm"&gt;
    &lt;fileset dir="htdocs/manual"&gt;
        &lt;include name="**/*.html"/&gt;
    &lt;/fileset&gt;
&lt;/ftp&gt;</pre>
<p>If <samp>apache.org</samp> ever switches to a Unix FTP server that uses the new all-numeric
format for timestamps, this version would become necessary.  It would accomplish the same
functionality as the previous example but would successfully handle the numeric timestamps.
The <var>systemTypeKey</var> is not necessary here but helps clarify what is going on.</p>
<pre>
&lt;ftp action="get"
     server="ftp.hypthetical.fr"
     userid="anonymous"
     password="me@myorg.com"
     defaultDateFormatConfig="d MMM yyyy"
     recentDateFormatConfig="d MMM HH:mm"
     serverLanguageCodeConfig="fr"&gt;
    &lt;fileset dir="htdocs/manual"&gt;
        &lt;include name="**/*.html"/&gt;
    &lt;/fileset&gt;
&lt;/ftp&gt;</pre>
<p>Logs into a UNIX FTP server at <samp>ftp.hypothetical.fr</samp> which displays dates with French
names in Standard European format, as <samp>anonymous</samp>, and recursively downloads
all <samp>.html</samp> files from default directory for that user into
the <samp>htdocs/manual</samp> directory on the local machine.</p>

<h3>Deleting files</h3>
<p>As you've probably guessed by now, you use nested fileset elements to select the files to delete
from the remote FTP server.  Again, the filesets are relative to the remote directory, not a local
directory.  In fact, the <var>dir</var> attribute of the fileset is ignored completely.</p>

<pre>
&lt;ftp action="del"
     server="ftp.apache.org"
     userid="anonymous"
     password="me@myorg.com"&gt;
    &lt;fileset&gt;
        &lt;include name="**/*.tmp"/&gt;
    &lt;/fileset&gt;
&lt;/ftp&gt;</pre>
<p>Logs in to <samp>ftp.apache.org</samp> as <samp>anonymous</samp> and tries to delete
all <samp>*.tmp</samp> files from the default directory for that user.  If you don't have permission
to delete a file, a BuildException is thrown.</p>
<h3>Listing Files</h3>
<pre>
&lt;ftp action="list"
     server="ftp.apache.org"
     userid="anonymous"
     password="me@myorg.com"
     listing="data/ftp.listing"&gt;
    &lt;fileset&gt;
        &lt;include name="**"/&gt;
    &lt;/fileset&gt;
&lt;/ftp&gt;</pre>
<p>This provides a file listing in <samp>data/ftp.listing</samp> of all the files on the FTP server
relative to the default directory of the <samp>anonymous</samp> user. The listing is in whatever
format the FTP server normally lists files.</p>

<h3>Creating directories</h3>
<p>Note that with the <q>mkdir</q> action, the directory to create is specified using
the <var>remotedir</var> attribute.</p>
<pre>
&lt;ftp action="mkdir"
     server="ftp.apache.org"
     userid="anonymous"
     password="me@myorg.com"
     remotedir="some/remote/dir"/&gt;</pre>
<p>This creates the directory <samp>some/remote/dir</samp> beneath the default root directory.  As
with all other actions, the directory separator character must be correct according to the desires
of the FTP server.</p>
<h3>Removing directories</h3>
<p>This action uses nested fileset elements to select the directories to remove from the remote FTP
server.  The filesets are relative to the remote directory, not a local directory.
The <var>dir</var> attribute of the fileset is ignored completely.  The directories to be removed
must be empty, or contain only other directories that have been also selected to be removed by the
filesets patterns, otherwise a BuildException will be thrown.  Also, if you don't have permission to
remove a directory, a BuildException is thrown.</p>

<pre>
&lt;ftp action="rmdir"
     server="ftp.apache.org"
     userid="anonymous"
     password="me@myorg.com"
     remotedir="/somedir" &gt;
    &lt;fileset&gt;
        &lt;include name="dira"/&gt;
        &lt;include name="dirb/**"/&gt;
    &lt;/fileset&gt;
&lt;/ftp&gt;</pre>
<p>Logs in to <samp>ftp.apache.org</samp> as <samp>anonymous</samp> and tries to
remove <samp>/somedir/dira</samp> directory and all the directories tree starting at, and
including, <samp>/somedir/dirb</samp>.  When removing the <samp>/somedir/dirb</samp> tree, it will
start at the leaves moving up to the root, so that when it tries to remove a directory it is sure
all the directories under it are already removed.  Obviously all the files in the tree must have
been already deleted.</p>
<p>As an example suppose you want to delete everything contained into <samp>/somedir</samp>, so
invoke first the <code>&lt;ftp&gt;</code> task with <var>action</var>=<q>delete</q>, then
with <var>action</var>=<q>rmdir</q> specifying in both cases <var>remotedir</var>=<q>/somedir</q>
and</p>
<pre>
&lt;fileset&gt;
    &lt;include name="**"/&gt;
&lt;/fileset&gt;</pre>
<p>The directory specified in the <var>remotedir</var> parameter is never selected for remove, so if
you need to remove it, specify its parent in <var>remotedir</var> parameter and include it in the
<code>&lt;fileset&gt;</code> pattern, like <samp>somedir/**</samp>.</p>

</body>
</html>