You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

ftp.html 27 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. <!DOCTYPE html>
  2. <!--
  3. Licensed to the Apache Software Foundation (ASF) under one or more
  4. contributor license agreements. See the NOTICE file distributed with
  5. this work for additional information regarding copyright ownership.
  6. The ASF licenses this file to You under the Apache License, Version 2.0
  7. (the "License"); you may not use this file except in compliance with
  8. the License. You may obtain a copy of the License at
  9. https://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing, software
  11. distributed under the License is distributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. limitations under the License.
  15. -->
  16. <html lang="en">
  17. <head>
  18. <link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
  19. <title>FTP Task</title>
  20. </head>
  21. <body>
  22. <h2 id="ftp">FTP</h2>
  23. <h3>Description</h3>
  24. <p>The <code>ftp</code> task implements a basic FTP client that can send, receive, list, delete
  25. files, and create directories. See below for descriptions and examples of how to perform each
  26. task.</p>
  27. <p><strong>Note</strong>: This task depends on external libraries not included in the Apache Ant
  28. distribution. See <a href="../install.html#commons-net">Library Dependencies</a> for more
  29. information. <em>Get the latest version of this library, for the best support in Ant.</em></p>
  30. <p>The <code>ftp</code> task attempts to determine what file system is in place on the FTP server.
  31. Supported server types are Unix, NT, OS2, VMS, and OS400. In addition, NT and OS400 servers which
  32. have been configured to display the directory in Unix style are also supported correctly.
  33. Otherwise, the system will default to Unix standards. <var>remotedir</var> must be specified in the
  34. exact syntax required by the FTP server. If the usual Unix conventions are not supported by the
  35. server, <var>separator</var> can be used to set the file separator that should be used instead.</p>
  36. <p>See the section on <a href="../dirtasks.html#directorybasedtasks">directory based tasks</a>, on
  37. how the inclusion/exclusion of files works, and how to write patterns.</p>
  38. <p>This task does not currently use the proxy information set by
  39. the <a href="setproxy.html"><code>&lt;setproxy&gt;</code></a> task, and cannot go through a firewall
  40. via socks.</p>
  41. <p><strong>Warning</strong>: there have been problems reported concerning
  42. the <code>ftp</code> <q>get</q> with the <var>newer</var> attribute. Problems might be due to
  43. format of <kbd>ls -l</kbd> differing from what is expected by commons-net, for instance due to
  44. specifics of language used by the FTP server in the directory listing. If you encounter such a
  45. problem, please send an email including a sample directory listing coming from your FTP server
  46. (<kbd>ls -l</kbd> on the FTP prompt).</p>
  47. <p>If you can connect but not upload or download, try setting the <var>passive</var> attribute
  48. to <q>true</q> to use the existing (open) channel, instead of having the server try to set up a new
  49. connection.</p>
  50. <h3>Parameters</h3>
  51. <table class="attr">
  52. <tr>
  53. <th scope="col">Attribute</th>
  54. <th scope="col">Description</th>
  55. <th scope="col">Required</th>
  56. </tr>
  57. <tr>
  58. <td>server</td>
  59. <td>the address of the remote FTP server.</td>
  60. <td>Yes</td>
  61. </tr>
  62. <tr>
  63. <td>port</td>
  64. <td>the port number of the remote FTP server.</td>
  65. <td>No; defaults to <q>21</q></td>
  66. </tr>
  67. <tr>
  68. <td>userid</td>
  69. <td>the login id to use on the FTP server.</td>
  70. <td>Yes</td>
  71. </tr>
  72. <tr>
  73. <td>password</td>
  74. <td>the login password to use on the FTP server.</td>
  75. <td>Yes</td>
  76. </tr>
  77. <tr>
  78. <td>account</td>
  79. <td>the account to use on the FTP server.
  80. <em>since Ant 1.7</em>.</td>
  81. <td>No</td>
  82. </tr>
  83. <tr>
  84. <td>remotedir</td>
  85. <td>remote directory on the FTP server see table below for detailed usage</td>
  86. <td>No</td>
  87. </tr>
  88. <tr>
  89. <td>action</td>
  90. <td>FTP action to perform. Currently
  91. supports <q>put</q>, <q>get</q>, <q>del</q>, <q>list</q>, <q>chmod</q>, <q>mkdir</q>, <q>rmdir</q>,
  92. and <q>site</q>.</td>
  93. <td>No; defaults to <q>send</q></td>
  94. </tr>
  95. <tr>
  96. <td>binary</td>
  97. <td>selects binary-mode (<q>yes</q>) or text-mode (<q>no</q>) transfers.</td>
  98. <td>No; defaults to <q>yes</q></td>
  99. </tr>
  100. <tr>
  101. <td>passive</td>
  102. <td>selects passive-mode (<q>yes</q>) transfers, for better through-firewall connectivity, at
  103. the price of performance.</td>
  104. <td>No; defaults to <q>no</q></td>
  105. </tr>
  106. <tr>
  107. <td>verbose</td>
  108. <td>displays information on each file transferred if set to <q>yes</q>.</td>
  109. <td>No; defaults to <q>no</q></td>
  110. </tr>
  111. <tr>
  112. <td>depends</td>
  113. <td>transfers only new or changed files if set to <q>yes</q>.</td>
  114. <td>No; defaults to <q>no</q></td>
  115. </tr>
  116. <tr>
  117. <td>newer</td>
  118. <td>a synonym for <var>depends</var>. See <var>timediffauto</var>
  119. and <var>timediffmillis</var></td>
  120. <td>No</td>
  121. </tr>
  122. <tr>
  123. <td>timediffauto</td>
  124. <td>set to <q>true</q> to make Ant calculate the time difference between client and
  125. server.<br/><em>requires write access in the remote directory</em><br/><em>Since Ant
  126. 1.6</em></td>
  127. <td>No</td>
  128. </tr>
  129. <tr id="timestampGranularity">
  130. <td>timestampGranularity</td>
  131. <td>Specify either <q>MINUTE</q> or <q>NONE</q> (you may specify <q></q> which is equivalent to
  132. not specifying a value, useful for property-file driven scripts). Allows override of the
  133. typical situation in <q>put</q> and <q>get</q> where local filesystem timestamps
  134. are <code>HH:mm:ss</code> and the typical FTP server's timestamps are <code>HH:mm</code>.
  135. This can throw off <var>uptodate</var> calculations. However, the default values should
  136. suffice for most applications.<br/><em>Since Ant 1.7</em></td>
  137. <td>No; only applies for <q>put</q> (default is <q>MINUTE</q>) and <q>get</q> (default
  138. is <q>NONE</q>; not as necessary because we have the <var>preservelastmodified</var>
  139. option)</td>
  140. </tr>
  141. <tr>
  142. <td>timediffmillis</td>
  143. <td><em><u>Deprecated</u></em>. Number of milliseconds to add to the time on the remote machine
  144. to get the time on the local machine. The <var>timestampGranularity</var> attribute (for
  145. which the default values should suffice in most situations), and
  146. the <var>serverTimeZoneConfig</var> option, should make this
  147. unnecessary. <var>serverTimeZoneConfig</var> does the math for you and also knows about
  148. Daylight Savings Time.<br/><em>Since Ant 1.6</em></td>
  149. <td>No</td>
  150. </tr>
  151. <tr>
  152. <td>separator</td>
  153. <td>sets the file separator used on the FTP server.</td>
  154. <td>No; defaults to <q>/</q></td>
  155. </tr>
  156. <tr>
  157. <td>umask</td>
  158. <td>sets the default file permissions for new files, Unix only.</td>
  159. <td>No</td>
  160. </tr>
  161. <tr>
  162. <td>chmod</td>
  163. <td>sets or changes file permissions for new or existing files, Unix only. If used with
  164. a <q>put</q> action, <q>chmod</q> will be issued for each file.</td>
  165. <td>No</td>
  166. </tr>
  167. <tr>
  168. <td>listing</td>
  169. <td>the file to write results of the <q>list</q> action.</td>
  170. <td>Yes, for the <q>list</q> action; ignored otherwise</td>
  171. </tr>
  172. <tr>
  173. <td>ignoreNoncriticalErrors</td>
  174. <td>flag which permits the task to ignore some non-fatal error codes sent by some servers during
  175. directory creation: wu-ftp in particular.</td>
  176. <td>No; defaults to <q>false</q></td>
  177. </tr>
  178. <tr>
  179. <td>skipFailedTransfers</td>
  180. <td>flag which enables unsuccessful file <q>put</q>, <q>delete</q> and <q>get</q> operations to
  181. be skipped with a warning and the remainder of the files still transferred.</td>
  182. <td>No; default to <q>false</q></td>
  183. </tr>
  184. <tr>
  185. <td>preservelastmodified</td>
  186. <td>Give the copied files the same last modified time as the original source files (applies to
  187. getting files only).</td>
  188. <td>No; defaults to <q>false</q></td>
  189. </tr>
  190. <tr>
  191. <td>retriesAllowed</td>
  192. <td>Set the number of retries allowed on an file-transfer operation. If a positive number is
  193. specified, each file transfer can fail up to that many times before the operation is failed.
  194. If <q>-1</q> or <q>forever</q> specified, the operation will keep trying until it
  195. succeeds.</td>
  196. <td>No; defaults to <q>0</q></td>
  197. </tr>
  198. <tr>
  199. <td>siteCommand</td>
  200. <td>Set the server-specific <code>SITE</code> command to execute if the <var>action</var>
  201. attribute has been specified as <q>site</q>.
  202. <td>No</td>
  203. </tr>
  204. <tr>
  205. <td>initialSiteCommand</td>
  206. <td>Set a server-specific <code>SITE</code> command to execute immediately after login.</td>
  207. <td>No</td>
  208. </tr>
  209. <tr>
  210. <td>enableRemoteVerification</td>
  211. <td>Whether data connection should be verified to connect to the same host as the control
  212. connection. This is a security measure that is enabled by default, but it may be useful to
  213. disable it in certain firewall scenarios. <em>since Ant 1.8.0</em></td>
  214. <td>No; default is <q>true</q></td>
  215. </tr>
  216. <tr>
  217. <td>dataTimeout</td>
  218. <td>Sets a timeout in milliseconds used when waiting for data on the data connection.
  219. A value of 0 means an infinite timeout.<em>since Ant 1.10.7</em></td>
  220. <td>No</td>
  221. </tr>
  222. <tr>
  223. <td>wakeUpTransferInterval</td>
  224. <td>Only use if proved to be necessary, interval in seconds on which a LIST command is triggered
  225. trigger a data connection (to avoid timeouts by the ftp server on no data connection).
  226. <em>since Ant 1.10.7</em></td>
  227. <td>No</td>
  228. </tr>
  229. <tr>
  230. <td colspan="3" class="left">
  231. <p><strong>The following attributes
  232. require <a href="https://commons.apache.org/net/download_net.cgi"
  233. target="_top">jakarta-commons-net-1.4.0 or greater</a>.</strong></p>
  234. <p>Use these options when the standard options don't work, because</p>
  235. <ul>
  236. <li>the server is in a different timezone and you need timestamp dependency checking</li>
  237. <li>the default timestamp formatting doesn't match the server display and list parsing
  238. therefore fails</li>
  239. </ul>
  240. <p>If none of these is specified, the default mechanism of letting the system auto-detect the
  241. server OS type based on the FTP <code>SYST</code> command and assuming standard formatting
  242. for that OS type will be used.</p>
  243. <p>To aid in property-file-based development where a build script is configured with property
  244. files, for any of these attributes, a value of <q></q> is equivalent to not specifying it.</p>
  245. <p>Please understand that these options are incompatible with the autodetection scheme. If
  246. any of these options is specified, (other than with a value of <q></q>) a system type must be
  247. chosen and if <var>systemTypeKey</var> is not specified, UNIX will be assumed. The philosophy
  248. behind this is that these options are for setting non-standard formats, and a build-script
  249. author who knows what system he is dealing with will know what options to need to be
  250. set. Otherwise, these options should be left alone and the default autodetection scheme can be
  251. used and will work in the majority of cases.</p>
  252. </td>
  253. </tr>
  254. <tr>
  255. <td>systemTypeKey</td>
  256. <td>Specifies the type of system in use on the server. Supported values
  257. are <q>UNIX</q>, <q>VMS</q>, <q>WINDOWS</q>, <q>OS/2</q>, <q>OS/400</q>, <q>MVS</q>. If not
  258. specified, (or specified as <q></q>) and if no other <var>xxxConfig</var> attributes are
  259. specified, the autodetection mechanism based on the FTP <code>SYST</code> command will be
  260. used.<br/><em>Since Ant 1.7</em></td>
  261. <td>No, but if any of the following <var>xxxConfig</var> attributes is specified, UNIX will be
  262. assumed, even if <q></q> is specified here.
  263. </td>
  264. </tr>
  265. <tr>
  266. <td>serverTimeZoneConfig</td>
  267. <td>Specify as a
  268. Java <a href="https://docs.oracle.com/javase/8/docs/api/java/util/TimeZone.html"
  269. target="_top">TimeZone</a> identifier, (e.g. <q>GMT</q>, <q>America/Chicago</q>
  270. or <q>Asia/Jakarta</q>) the timezone used by the server for timestamps. This enables
  271. timestamp dependency checking even when the server is in a different time zone from the
  272. client. Time Zones know, also, about daylight savings time, and do not require you to
  273. calculate milliseconds of difference. If not specified, (or specified as <q></q>), the time
  274. zone of the client is assumed.<br/><em>Since Ant 1.7</em></td>
  275. <td>No</td>
  276. </tr>
  277. <tr>
  278. <td>defaultDateFormatConfig</td>
  279. <td>Specify in
  280. Java <a href="https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html"
  281. target="_top">SimpleDateFormat</a> notation, (e.g. <q>yyyy-MM-dd</q>), the date format
  282. generally used by the FTP server to parse dates. In some cases this will be the only date
  283. format used. In others, (<q>unix</q> for example) this will be used for dates older than a
  284. year old. (See <var>recentDateFormatConfig</var>). When specified as <q></q>, default value
  285. will be used.<br/><em>Since Ant 1.7</em></td>
  286. <td>No; defaults to default date format for the system type indicated
  287. by <var>systemTypeKey</var></td>
  288. </tr>
  289. <tr>
  290. <td>recentDateFormatConfig</td>
  291. <td>Specify in
  292. Java <a href="https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html"
  293. target="_top">SimpleDateFormat</a> notation, (e.g. <q>MMM dd hh:mm</q>) the date format used
  294. by the FTP server to parse dates less than a year old. If not specified (or specified
  295. as <q></q>), and if the system type indicated by the <var>systemTypeKey</var> uses a recent
  296. date format, its standard format will be used.<br/><em>Since Ant 1.7</em></td>
  297. <td>No</td>
  298. </tr>
  299. <tr>
  300. <td>serverLanguageCodeConfig</td>
  301. <td>a <a href="http://www.mathguide.de/info/tools/languagecode.html" target="_top">two-letter
  302. ISO-639 language code</a> used to specify the language used by the server to format month
  303. names. This only needs to be specified when the server uses non-numeric abbreviations for
  304. months in its date listings in a language other than English. This appears to be becoming
  305. rarer and rarer, as commonly distributed FTP servers seem increasingly to use English or
  306. all-numeric formats. Languages supported are:
  307. <ul>
  308. <li><q>en</q>&mdash;English</li>
  309. <li><q>fr</q>&mdash;French</li>
  310. <li><q>de</q>&mdash;German</li>
  311. <li><q>it</q>&mdash;Italian</li>
  312. <li><q>es</q>&mdash;Spanish</li>
  313. <li><q>pt</q>&mdash;Portuguese</li>
  314. <li><q>da</q>&mdash;Danish</li>
  315. <li><q>sv</q>&mdash;Swedish</li>
  316. <li><q>no</q>&mdash;Norwegian</li>
  317. <li><q>nl</q>&mdash;Dutch</li>
  318. <li><q>ro</q>&mdash;Romanian</li>
  319. <li><q>sq</q>&mdash;Albanian</li>
  320. <li><q>sh</q>&mdash;Serbo-Croatian</li>
  321. <li><q>sk</q>&mdash;Slovak</li>
  322. <li><q>sl</q>&mdash;Slovenian</li>
  323. </ul>
  324. If you require a language other than the above, see also the <var>shortMonthNamesConfig</var>
  325. attribute.<br/><em>Since Ant 1.7</em></td>
  326. <td>No</td>
  327. </tr>
  328. <tr>
  329. <td>shortMonthNamesConfig</td>
  330. <td>specify the month abbreviations used on the server in file timestamp dates as a
  331. pipe-delimited string for each month. For example, a set of month names used by a hypothetical
  332. Icelandic FTP server might conceivably be specified
  333. as <q>jan|feb|mar|apr|ma&iacute;|j&uacute;n|j&uacute;l|&aacute;g&uacute;|sep|okt|n&oacute;v|des</q>.
  334. This attribute exists primarily to support languages not supported by
  335. the <var>serverLanguageCode</var> attribute.<br/><em>Since Ant 1.7</em></td>
  336. <td>No</td>
  337. </tr>
  338. </table>
  339. <h3>Note about <var>remotedir</var> attribute</h3>
  340. <table>
  341. <thead>
  342. <tr>
  343. <th scope="col">Action</th>
  344. <th scope="col">meaning of <var>remotedir</var></th>
  345. <th scope="col">use of nested <var>fileset</var>(s)</th>
  346. </tr>
  347. </thead>
  348. <tbody>
  349. <tr>
  350. <td><q>send</q>/<q>put</q></td>
  351. <td>base directory to which the files are sent</td>
  352. <td>they are used normally and evaluated on the local machine</td>
  353. </tr>
  354. <tr>
  355. <td><q>recv</q>/<q>get</q></td>
  356. <td>base directory from which the files are retrieved</td>
  357. <td>the remote files located under the <var>remotedir</var> matching the include/exclude
  358. patterns of the <var>fileset</var></td>
  359. </tr>
  360. <tr>
  361. <td><q>del</q>/<q>delete</q></td>
  362. <td>base directory from which files get deleted</td>
  363. <td>the remote files located under the <var>remotedir</var> matching the include/exclude
  364. patterns of the <var>fileset</var></td>
  365. </tr>
  366. <tr>
  367. <td><q>list</q></td>
  368. <td>base directory from which files are listed</td>
  369. <td>the remote files located under the <var>remotedir</var> matching the include/exclude
  370. patterns of the <var>fileset</var></td>
  371. </tr>
  372. <tr>
  373. <td><q>mkdir</q></td>
  374. <td>directory to create</td>
  375. <td><em>not used</em></td>
  376. </tr>
  377. <tr>
  378. <td><q>chmod</q></td>
  379. <td>base directory from which the mode of files get changed</td>
  380. <td>the remote files located under the <var>remotedir</var> matching the include/exclude
  381. patterns of the <var>fileset</var></td>
  382. </tr>
  383. <tr>
  384. <td><q>rmdir</q></td>
  385. <td>base directory from which directories get removed</td>
  386. <td>the remote directories located under the <var>remotedir</var> matching the include/exclude
  387. patterns of the <var>fileset</var></td>
  388. </tr>
  389. </tbody>
  390. </table>
  391. <h3>Parameters specified as nested elements</h3>
  392. <h4>fileset</h4>
  393. <p>The <code>ftp</code> task supports any number of
  394. nested <a href="../Types/fileset.html"><code>&lt;fileset&gt;</code></a> elements to specify the
  395. files to be retrieved, or deleted, or listed, or whose mode you want to change.</p>
  396. <p>The attribute <var>followsymlinks</var> of <code>fileset</code> is supported on local
  397. (<q>put</q>) as well as remote (<q>get</q>, <q>chmod</q>, <q>delete</q>, <q>list</q>) filesets. <em>Before Ant
  398. 1.6 there was no support of symbolic links in remote filesets. In order to exclude symbolic links
  399. (preserve the behavior of Ant 1.5.x and older), you need to explicitly set <var>followsymlinks</var>
  400. to <q>false</q>.</em> On remote filesets hidden files are not checked for being symbolic links.
  401. Hidden files are currently assumed to not be symbolic links.</p>
  402. <h3>Sending files</h3>
  403. <p>The easiest way to describe how to send files is with a couple of examples.</p>
  404. <p>Log in to <samp>ftp.apache.org</samp> as <samp>anonymous</samp> and upload all files in
  405. the <samp>htdocs/manual</samp> directory to the default directory for that user.</p>
  406. <pre>
  407. &lt;ftp server="ftp.apache.org"
  408. userid="anonymous"
  409. password="me@myorg.com"&gt;
  410. &lt;fileset dir="htdocs/manual"/&gt;
  411. &lt;/ftp&gt;</pre>
  412. <p>Log in to <samp>ftp.apache.org</samp> as <samp>anonymous</samp> and upload all new or changed
  413. files in the <samp>htdocs/manual</samp> directory to the <samp>incoming</samp> directory relative to
  414. the default directory for <samp>anonymous</samp>.</p>
  415. <pre>
  416. &lt;ftp server="ftp.apache.org"
  417. remotedir="incoming"
  418. userid="anonymous"
  419. password="me@myorg.com"
  420. depends="yes"&gt;
  421. &lt;fileset dir="htdocs/manual"/&gt;
  422. &lt;/ftp&gt;</pre>
  423. <p>Log in to <samp>ftp.apache.org</samp> at port <samp>2121</samp> as <samp>coder</samp> with
  424. password <samp>java1</samp> and upload all new or changed HTML files in
  425. the <samp>htdocs/manual</samp> directory to the <samp>/pub/incoming</samp> directory. The files are
  426. transferred in text mode. Passive mode has been switched on to send files from behind a
  427. firewall.</p>
  428. <pre>
  429. &lt;ftp server="ftp.apache.org"
  430. port="2121"
  431. remotedir="/pub/incoming"
  432. userid="coder"
  433. password="java1"
  434. passive="yes"
  435. depends="yes"
  436. binary="no"&gt;
  437. &lt;fileset dir="htdocs/manual"&gt;
  438. &lt;include name="**/*.html"/&gt;
  439. &lt;/fileset&gt;
  440. &lt;/ftp&gt;</pre>
  441. <p>Log in to a Windows server at <samp>ftp.hypothetical.india.org</samp> at port <samp>2121</samp>
  442. as <samp>coder</samp> with password <samp>java1</samp> and upload all new or changed (accounting for
  443. timezone differences) HTML files in the <samp>htdocs/manual</samp> directory to
  444. the <samp>/pub/incoming</samp> directory. The files are transferred in text mode.</p>
  445. <pre>
  446. &lt;ftp server="ftp.hypothetical.india.org"
  447. port="2121"
  448. remotedir="/pub/incoming"
  449. userid="coder"
  450. password="java1"
  451. depends="yes"
  452. binary="no"
  453. systemTypeKey="Windows"
  454. serverTimeZoneConfig="India/Calcutta"&gt;
  455. &lt;fileset dir="htdocs/manual"&gt;
  456. &lt;include name="**/*.html"/&gt;
  457. &lt;/fileset&gt;
  458. &lt;/ftp&gt;</pre>
  459. <p>Log in to the Windows-based <samp>ftp.nt.org</samp> as <samp>coder</samp> with
  460. password <samp>java1</samp> and upload all HTML files in the <samp>htdocs/manual</samp> directory to
  461. the <samp>c:\uploads</samp> directory. Progress messages are displayed as each file is uploaded.</p>
  462. <pre>
  463. &lt;ftp server="ftp.nt.org"
  464. remotedir="c:\uploads"
  465. userid="coder"
  466. password="java1"
  467. separator="\"
  468. verbose="yes"&gt;
  469. &lt;fileset dir="htdocs/manual"&gt;
  470. &lt;include name="**/*.html"/&gt;
  471. &lt;/fileset&gt;
  472. &lt;/ftp&gt;</pre>
  473. <h3>Getting files</h3>
  474. <p>Getting files from an FTP server works pretty much the same way as sending them does. The only
  475. difference is that the nested filesets use the <var>remotedir</var> attribute as the base directory
  476. for the files on the FTP server, and the <var>dir</var> attribute as the local directory to put the
  477. files into. The file structure from the FTP site is preserved on the local machine.</p>
  478. <p>Log in to <samp>ftp.apache.org</samp> as <samp>anonymous</samp> and recursively download
  479. all <samp>.html</samp> files from default directory for that user into
  480. the <samp>htdocs/manual</samp> directory on the local machine.</p>
  481. <pre>
  482. &lt;ftp action="get"
  483. server="ftp.apache.org"
  484. userid="anonymous"
  485. password="me@myorg.com"&gt;
  486. &lt;fileset dir="htdocs/manual"&gt;
  487. &lt;include name="**/*.html"/&gt;
  488. &lt;/fileset&gt;
  489. &lt;/ftp&gt;</pre>
  490. <p>If <samp>apache.org</samp> ever switches to a Unix FTP server that uses the new all-numeric
  491. format for timestamps, this version would become necessary. It would accomplish the same
  492. functionality as the previous example but would successfully handle the numeric
  493. timestamps. The <var>systemTypeKey</var> is not necessary here but helps clarify what is going
  494. on.</p>
  495. <pre>
  496. &lt;ftp action="get"
  497. server="ftp.apache.org"
  498. userid="anonymous"
  499. password="me@myorg.com"
  500. systemTypeKey="UNIX"
  501. defaultDateFormatConfig="yyyy-MM-dd HH:mm"&gt;
  502. &lt;fileset dir="htdocs/manual"&gt;
  503. &lt;include name="**/*.html"/&gt;
  504. &lt;/fileset&gt;
  505. &lt;/ftp&gt;</pre>
  506. <p>Log into a UNIX FTP server at <samp>ftp.hypothetical.fr</samp> which displays dates with French
  507. names in Standard European format, as <samp>anonymous</samp>, and recursively download
  508. all <samp>.html</samp> files from default directory for that user into
  509. the <samp>htdocs/manual</samp> directory on the local machine.</p>
  510. <pre>
  511. &lt;ftp action="get"
  512. server="ftp.hypthetical.fr"
  513. userid="anonymous"
  514. password="me@myorg.com"
  515. defaultDateFormatConfig="d MMM yyyy"
  516. recentDateFormatConfig="d MMM HH:mm"
  517. serverLanguageCodeConfig="fr"&gt;
  518. &lt;fileset dir="htdocs/manual"&gt;
  519. &lt;include name="**/*.html"/&gt;
  520. &lt;/fileset&gt;
  521. &lt;/ftp&gt;</pre>
  522. <h3>Deleting files</h3>
  523. <p>As you've probably guessed by now, you use nested fileset elements to select the files to delete
  524. from the remote FTP server. Again, the filesets are relative to the remote directory, not a local
  525. directory. In fact, the <var>dir</var> attribute of the fileset is ignored completely.</p>
  526. <p>Log in to <samp>ftp.apache.org</samp> as <samp>anonymous</samp> and try to delete
  527. all <samp>*.tmp</samp> files from the default directory for that user. If you don't have permission
  528. to delete a file, a <code>BuildException</code> is thrown.</p>
  529. <pre>
  530. &lt;ftp action="del"
  531. server="ftp.apache.org"
  532. userid="anonymous"
  533. password="me@myorg.com"&gt;
  534. &lt;fileset&gt;
  535. &lt;include name="**/*.tmp"/&gt;
  536. &lt;/fileset&gt;
  537. &lt;/ftp&gt;</pre>
  538. <h3>Listing Files</h3>
  539. <p>Get a file listing in <samp>data/ftp.listing</samp> of all the files on the FTP server relative
  540. to the default directory of the <samp>anonymous</samp> user. The listing is in whatever format the
  541. FTP server normally lists files.</p>
  542. <pre>
  543. &lt;ftp action="list"
  544. server="ftp.apache.org"
  545. userid="anonymous"
  546. password="me@myorg.com"
  547. listing="data/ftp.listing"&gt;
  548. &lt;fileset&gt;
  549. &lt;include name="**"/&gt;
  550. &lt;/fileset&gt;
  551. &lt;/ftp&gt;</pre>
  552. <h3>Creating directories</h3>
  553. <p>Note that with the <q>mkdir</q> action, the directory to create is specified using
  554. the <var>remotedir</var> attribute.</p>
  555. <p>Create the directory <samp>some/remote/dir</samp> beneath the default root directory. As with all
  556. other actions, the directory separator character must be correct according to the desires of the FTP
  557. server.</p>
  558. <pre>
  559. &lt;ftp action="mkdir"
  560. server="ftp.apache.org"
  561. userid="anonymous"
  562. password="me@myorg.com"
  563. remotedir="some/remote/dir"/&gt;</pre>
  564. <h3>Removing directories</h3>
  565. <p>This action uses nested fileset elements to select the directories to remove from the remote FTP
  566. server. The filesets are relative to the remote directory, not a local directory. The <var>dir</var>
  567. attribute of the fileset is ignored completely. The directories to be removed must be empty, or
  568. contain only other directories that have been also selected to be removed by the filesets patterns,
  569. otherwise a <code>BuildException</code> will be thrown. Also, if you don't have permission to remove
  570. a directory, a <code>BuildException</code> is thrown.</p>
  571. <p>Log in to <samp>ftp.apache.org</samp> as <samp>anonymous</samp> and try to
  572. remove <samp>/somedir/dira</samp> directory and all the directory tree starting at, and
  573. including, <samp>/somedir/dirb</samp>. When removing the <samp>/somedir/dirb</samp> tree, the task
  574. starts at the leaves moving up to the root, so that when it tries to remove a directory it is sure
  575. all the directories under it are already removed. Obviously all the files in the tree must have
  576. been already deleted.</p>
  577. <pre>
  578. &lt;ftp action="rmdir"
  579. server="ftp.apache.org"
  580. userid="anonymous"
  581. password="me@myorg.com"
  582. remotedir="/somedir" &gt;
  583. &lt;fileset&gt;
  584. &lt;include name="dira"/&gt;
  585. &lt;include name="dirb/**"/&gt;
  586. &lt;/fileset&gt;
  587. &lt;/ftp&gt;</pre>
  588. <p>As an example suppose you want to delete everything contained in <samp>/somedir</samp>, so invoke
  589. first the <code>&lt;ftp&gt;</code> task with <var>action</var>=<q>delete</q>, then
  590. with <var>action</var>=<q>rmdir</q> specifying in both cases <var>remotedir</var>=<q>/somedir</q>
  591. and</p>
  592. <pre>
  593. &lt;fileset&gt;
  594. &lt;include name="**"/&gt;
  595. &lt;/fileset&gt;</pre>
  596. <p>The directory specified in the <var>remotedir</var> parameter is never selected for remove, so if
  597. you need to remove it, specify its parent in <var>remotedir</var> parameter and include it in the
  598. <code>&lt;fileset&gt;</code> pattern, like <samp>somedir/**</samp>.</p>
  599. </body>
  600. </html>