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 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. <!--
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. -->
  15. <html>
  16. <head>
  17. <meta http-equiv="Content-Language" content="en-us">
  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 <code>ls -l</code> 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. (<code>ls -l</code> 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>Attribute</th>
  54. <th>Description</th>
  55. <th>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>, <q>NONE</q>, (or you may specify <q></q> which is equivalent
  132. to 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 in <q>put</q> and <q>get</q> where the default values are <q>MINUTE</q>
  138. for <code>PUT</code> and <q>NONE</q> for <code>GET</code>. (It is not as necessary
  139. in <q>get</q> because we have the <var>preservelastmodified</var> 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, <code>chmod</code> 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. Required for the <q>list</q> action,
  170. ignored otherwise.</td>
  171. <td>No</td>
  172. </tr>
  173. <tr>
  174. <td>ignoreNoncriticalErrors</td>
  175. <td>flag which permits the task to ignore some non-fatal error codes sent by some servers during
  176. directory creation: wu-ftp in particular.</td>
  177. <td>No; defaults to <q>false</q></td>
  178. </tr>
  179. <tr>
  180. <td>skipFailedTransfers</td>
  181. <td>flag which enables unsuccessful file <q>put</q>, <q>delete</q> and <q>get</q> operations to
  182. be skipped with a warning and the remainder of the files still transferred.</td>
  183. <td>No; default to <q>false</q></td>
  184. </tr>
  185. <tr>
  186. <td>preservelastmodified</td>
  187. <td>Give the copied files the same last modified time as the original source files (applies to
  188. getting files only). (<strong>Note</strong>: Ignored on Java 1.1)</td>
  189. <td>No; defaults to <q>false</q></td>
  190. </tr>
  191. <tr>
  192. <td>retriesAllowed</td>
  193. <td>Set the number of retries allowed on an file-transfer operation. If a positive number is
  194. specified, each file transfer can fail up to that many times before the operation is failed.
  195. If <q>-1</q> or <q>forever</q> specified, the operation will keep trying until it
  196. succeeds.</td>
  197. <td>No; defaults to <q>0</q></td>
  198. </tr>
  199. <tr>
  200. <td>siteCommand</td>
  201. <td>Set the server-specific <code>SITE</code> command to execute if the <var>action</var>
  202. attribute has been specified as <q>site</q>.
  203. <td>No</td>
  204. </tr>
  205. <tr>
  206. <td>initialSiteCommand</td>
  207. <td>Set a server-specific <code>SITE</code> command to execute immediately after login.</td>
  208. <td>No</td>
  209. </tr>
  210. <tr>
  211. <td>enableRemoteVerification</td>
  212. <td>Whether data connection should be verified to connect to the same host as the control
  213. connection. This is a security measure that is enabled by default, but it may be useful to
  214. disable it in certain firewall scenarios. <em>since Ant 1.8.0</em></td>
  215. <td>No; default is <q>true</q></td>
  216. </tr>
  217. <tr>
  218. <td colspan="3" class="left">
  219. <p><strong>The following attributes
  220. require <a href="https://commons.apache.org/net/download_net.cgi"
  221. target="_top">jakarta-commons-net-1.4.0 or greater</a>.</strong></p>
  222. <p>Use these options when the standard options don't work, because</p>
  223. <ul>
  224. <li>the server is in a different timezone and you need timestamp dependency checking</li>
  225. <li>the default timestamp formatting doesn't match the server display and list parsing
  226. therefore fails</li>
  227. </ul>
  228. <p>If none of these is specified, the default mechanism of letting the system auto-detect the
  229. server OS type based on the FTP <code>SYST</code> command and assuming standard formatting
  230. for that OS type will be used.</p>
  231. <p>To aid in property-file-based development where a build script is configured with property
  232. files, for any of these attributes, a value of <q></q> is equivalent to not specifying it.</p>
  233. <p>Please understand that these options are incompatible with the autodetection scheme. If
  234. any of these options is specified, (other than with a value of <q></q>) a system type must be
  235. chosen and if <var>systemTypeKey</var> is not specified, UNIX will be assumed. The philosophy
  236. behind this is that these options are for setting non-standard formats, and a build-script
  237. author who knows what system he is dealing with will know what options to need to be
  238. set. Otherwise, these options should be left alone and the default autodetection scheme can be
  239. used and will work in the majority of cases.</p>
  240. </td>
  241. </tr>
  242. <tr>
  243. <td>systemTypeKey</td>
  244. <td>Specifies the type of system in use on the server. Supported values
  245. are <q>UNIX</q>, <q>VMS</q>, <q>WINDOWS</q>, <q>OS/2</q>, <q>OS/400</q>, <q>MVS</q>. If not
  246. specified, (or specified as <q></q>) and if no other <var>xxxConfig</var> attributes are
  247. specified, the autodetection mechanism based on the FTP <code>SYST</code> command will be
  248. used.<br/><em>Since Ant 1.7</em></td>
  249. <td>No, but if any of the following <var>xxxConfig</var> attributes is specified, UNIX will be
  250. assumed, even if <q></q> is specified here.
  251. </td>
  252. </tr>
  253. <tr>
  254. <td>serverTimeZoneConfig</td>
  255. <td>Specify as a
  256. Java <a href="https://docs.oracle.com/javase/8/docs/api/java/util/TimeZone.html"
  257. target="_top">TimeZone</a> identifier, (e.g. <q>GMT</q>, <q>America/Chicago</q>
  258. or <q>Asia/Jakarta</q>) the timezone used by the server for timestamps. This enables
  259. timestamp dependency checking even when the server is in a different time zone from the
  260. client. Time Zones know, also, about daylight savings time, and do not require you to
  261. calculate milliseconds of difference. If not specified, (or specified as <q></q>), the time
  262. zone of the client is assumed.<br/><em>Since Ant 1.7</em></td>
  263. <td>No</td>
  264. </tr>
  265. <tr>
  266. <td>defaultDateFormatConfig</td>
  267. <td>Specify in
  268. Java <a href="https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html"
  269. target="_top">SimpleDateFormat</a> notation, (e.g. <q>yyyy-MM-dd</q>), the date format
  270. generally used by the FTP server to parse dates. In some cases this will be the only date
  271. format used. In others, (<q>unix</q> for example) this will be used for dates older than a
  272. year old. (See <var>recentDateFormatConfig</var>). When specified as <q></q>, default value
  273. will be used.<br/><em>Since Ant 1.7</em></td>
  274. <td>No; defaults to default date format for the system type indicated
  275. by <var>systemTypeKey</var></td>
  276. </tr>
  277. <tr>
  278. <td>recentDateFormatConfig</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>MMM dd hh:mm</q>) the date format used
  282. by the FTP server to parse dates less than a year old. If not specified (or specified
  283. as <q></q>), and if the system type indicated by the <var>systemTypeKey</var> uses a recent
  284. date format, its standard format will be used.<br/><em>Since Ant 1.7</em></td>
  285. <td>No</td>
  286. </tr>
  287. <tr>
  288. <td>serverLanguageCodeConfig</td>
  289. <td>a <a href="http://www.mathguide.de/info/tools/languagecode.html" target="_top">two-letter
  290. ISO-639 language code</a> used to specify the language used by the server to format month
  291. names. This only needs to be specified when the server uses non-numeric abbreviations for
  292. months in its date listings in a language other than English. This appears to be becoming
  293. rarer and rarer, as commonly distributed FTP servers seem increasingly to use English or
  294. all-numeric formats. Languages supported are:
  295. <ul>
  296. <li><q>en</q>&mdash;English</li>
  297. <li><q>fr</q>&mdash;French</li>
  298. <li><q>de</q>&mdash;German</li>
  299. <li><q>it</q>&mdash;Italian</li>
  300. <li><q>es</q>&mdash;Spanish</li>
  301. <li><q>pt</q>&mdash;Portuguese</li>
  302. <li><q>da</q>&mdash;Danish</li>
  303. <li><q>sv</q>&mdash;Swedish</li>
  304. <li><q>no</q>&mdash;Norwegian</li>
  305. <li><q>nl</q>&mdash;Dutch</li>
  306. <li><q>ro</q>&mdash;Romanian</li>
  307. <li><q>sq</q>&mdash;Albanian</li>
  308. <li><q>sh</q>&mdash;Serbo-Croatian</li>
  309. <li><q>sk</q>&mdash;Slovak</li>
  310. <li><q>sl</q>&mdash;Slovenian</li>
  311. </ul>
  312. If you require a language other than the above, see also the <var>shortMonthNamesConfig</var>
  313. attribute.<br/><em>Since Ant 1.7</em></td>
  314. <td>No</td>
  315. </tr>
  316. <tr>
  317. <td>shortMonthNamesConfig</td>
  318. <td>specify the month abbreviations used on the server in file timestamp dates as a
  319. pipe-delimited string for each month. For example, a set of month names used by a hypothetical
  320. Icelandic FTP server might conceivably be specified
  321. as <q>jan|feb|mar|apr|ma&iacute;|j&uacute;n|j&uacute;l|&aacute;g&uacute;|sep|okt|n&oacute;v|des</q>.
  322. This attribute exists primarily to support languages not supported by
  323. the <var>serverLanguageCode</var> attribute.<br/><em>Since Ant 1.7</em></td>
  324. <td>No</td>
  325. </tr>
  326. </table>
  327. <h3>Note about <var>remotedir</var> attribute</h3>
  328. <table>
  329. <thead>
  330. <tr>
  331. <th>Action</th>
  332. <th>meaning of <var>remotedir</var></th>
  333. <th>use of nested <var>fileset</var>(s)</th>
  334. </tr>
  335. </thead>
  336. <tbody>
  337. <tr>
  338. <td><q>send</q>/<q>put</q></td>
  339. <td>base directory to which the files are sent</td>
  340. <td>they are used normally and evaluated on the local machine</td>
  341. </tr>
  342. <tr>
  343. <td><q>recv</q>/<q>get</q></td>
  344. <td>base directory from which the files are retrieved</td>
  345. <td>the remote files located under the <var>remotedir</var> matching the include/exclude
  346. patterns of the <var>fileset</var></td>
  347. </tr>
  348. <tr>
  349. <td><q>del</q>/<q>delete</q></td>
  350. <td>base directory from which files get deleted</td>
  351. <td>the remote files located under the <var>remotedir</var> matching the include/exclude
  352. patterns of the <var>fileset</var></td>
  353. </tr>
  354. <tr>
  355. <td><q>list</q></td>
  356. <td>base directory from which files are listed</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>mkdir</q></td>
  362. <td>directory to create</td>
  363. <td><em>not used</em></td>
  364. </tr>
  365. <tr>
  366. <td><q>chmod</q></td>
  367. <td>base directory from which the mode of files get changed</td>
  368. <td>the remote files located under the <var>remotedir</var> matching the include/exclude
  369. patterns of the <var>fileset</var></td>
  370. </tr>
  371. <tr>
  372. <td><q>rmdir</q></td>
  373. <td>base directory from which directories get removed</td>
  374. <td>the remote directories located under the <var>remotedir</var> matching the include/exclude
  375. patterns of the <var>fileset</var></td>
  376. </tr>
  377. </tbody>
  378. </table>
  379. <h3>Parameters specified as nested elements</h3>
  380. <h4>fileset</h4>
  381. <p>The <code>ftp</code> task supports any number of
  382. nested <a href="../Types/fileset.html"><code>&lt;fileset&gt;</code></a> elements to specify the
  383. files to be retrieved, or deleted, or listed, or whose mode you want to change.</p>
  384. <p>The attribute <var>followsymlinks</var> of <code>fileset</code> is supported on local
  385. (<q>put</q>) as well as remote (<q>get</q>, <q>chmod</q>, <q>delete</q>) filesets. <em>Before Ant
  386. 1.6 there was no support of symbolic links in remote filesets. In order to exclude symbolic links
  387. (preserve the behavior of Ant 1.5.x and older), you need to explicitly set <var>followsymlinks</var>
  388. to <q>false</q>.</em> On remote filesets hidden files are not checked for being symbolic links.
  389. Hidden files are currently assumed to not be symbolic links.</p>
  390. <h3>Sending files</h3>
  391. <p>The easiest way to describe how to send files is with a couple of examples:</p>
  392. <pre>
  393. &lt;ftp server="ftp.apache.org"
  394. userid="anonymous"
  395. password="me@myorg.com"&gt;
  396. &lt;fileset dir="htdocs/manual"/&gt;
  397. &lt;/ftp&gt;</pre>
  398. <p>Logs in to <samp>ftp.apache.org</samp> as <samp>anonymous</samp> and uploads all files in
  399. the <samp>htdocs/manual</samp> directory to the default directory for that user.</p>
  400. <pre>
  401. &lt;ftp server="ftp.apache.org"
  402. remotedir="incoming"
  403. userid="anonymous"
  404. password="me@myorg.com"
  405. depends="yes"&gt;
  406. &lt;fileset dir="htdocs/manual"/&gt;
  407. &lt;/ftp&gt;</pre>
  408. <p>Logs in to <samp>ftp.apache.org</samp> as <samp>anonymous</samp> and uploads all new or changed
  409. files in the <samp>htdocs/manual</samp> directory to the <samp>incoming</samp> directory relative to
  410. the default directory for <samp>anonymous</samp>.</p>
  411. <pre>
  412. &lt;ftp server="ftp.apache.org"
  413. port="2121"
  414. remotedir="/pub/incoming"
  415. userid="coder"
  416. password="java1"
  417. passive="yes"
  418. depends="yes"
  419. binary="no"&gt;
  420. &lt;fileset dir="htdocs/manual"&gt;
  421. &lt;include name="**/*.html"/&gt;
  422. &lt;/fileset&gt;
  423. &lt;/ftp&gt;</pre>
  424. <p>Logs in to <samp>ftp.apache.org</samp> at port <samp>2121</samp> as <samp>coder</samp> with
  425. password <samp>java1</samp> and uploads all new or changed HTML files in
  426. the <samp>htdocs/manual</samp> directory to the <samp>/pub/incoming</samp> directory. The files are
  427. transferred in text mode. Passive mode has been switched on to send files from behind a
  428. firewall.</p>
  429. <pre>
  430. &lt;ftp server="ftp.hypothetical.india.org"
  431. port="2121"
  432. remotedir="/pub/incoming"
  433. userid="coder"
  434. password="java1"
  435. depends="yes"
  436. binary="no"
  437. systemTypeKey="Windows"
  438. serverTimeZoneConfig="India/Calcutta"&gt;
  439. &lt;fileset dir="htdocs/manual"&gt;
  440. &lt;include name="**/*.html"/&gt;
  441. &lt;/fileset&gt;
  442. &lt;/ftp&gt;</pre>
  443. <p>Logs in to a Windows server at <samp>ftp.hypothetical.india.org</samp> at port <samp>2121</samp>
  444. as <samp>coder</samp> with password <samp>java1</samp> and uploads all new or changed (accounting
  445. for timezone differences) HTML files in the <samp>htdocs/manual</samp> directory to
  446. the <samp>/pub/incoming</samp> directory. The files are transferred in text mode.</p>
  447. <pre>
  448. &lt;ftp server="ftp.nt.org"
  449. remotedir="c:\uploads"
  450. userid="coder"
  451. password="java1"
  452. separator="\"
  453. verbose="yes"&gt;
  454. &lt;fileset dir="htdocs/manual"&gt;
  455. &lt;include name="**/*.html"/&gt;
  456. &lt;/fileset&gt;
  457. &lt;/ftp&gt;</pre>
  458. <p>Logs in to the Windows-based <samp>ftp.nt.org</samp> as <samp>coder</samp> with
  459. password <samp>java1</samp> and uploads all HTML files in the <samp>htdocs/manual</samp> directory
  460. to the <samp>c:\uploads</samp> directory. Progress messages are displayed as each file is
  461. uploaded.</p>
  462. <h3>Getting files</h3>
  463. <p>Getting files from an FTP server works pretty much the same way as sending them does. The only
  464. difference is that the nested filesets use the <var>remotedir</var> attribute as the base directory
  465. for the files on the FTP server, and the <var>dir</var> attribute as the local directory to put the
  466. files into. The file structure from the FTP site is preserved on the local machine.</p>
  467. <pre>
  468. &lt;ftp action="get"
  469. server="ftp.apache.org"
  470. userid="anonymous"
  471. password="me@myorg.com"&gt;
  472. &lt;fileset dir="htdocs/manual"&gt;
  473. &lt;include name="**/*.html"/&gt;
  474. &lt;/fileset&gt;
  475. &lt;/ftp&gt;</pre>
  476. <p>Logs in to <samp>ftp.apache.org</samp> as <samp>anonymous</samp> and recursively downloads
  477. all <samp>.html</samp> files from default directory for that user into
  478. the <samp>htdocs/manual</samp> directory on the local machine.</p>
  479. <pre>
  480. &lt;ftp action="get"
  481. server="ftp.apache.org"
  482. userid="anonymous"
  483. password="me@myorg.com"
  484. systemTypeKey="UNIX"
  485. defaultDateFormatConfig="yyyy-MM-dd HH:mm"&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 timestamps.
  493. The <var>systemTypeKey</var> is not necessary here but helps clarify what is going on.</p>
  494. <pre>
  495. &lt;ftp action="get"
  496. server="ftp.hypthetical.fr"
  497. userid="anonymous"
  498. password="me@myorg.com"
  499. defaultDateFormatConfig="d MMM yyyy"
  500. recentDateFormatConfig="d MMM HH:mm"
  501. serverLanguageCodeConfig="fr"&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>Logs 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 downloads
  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. <h3>Deleting files</h3>
  511. <p>As you've probably guessed by now, you use nested fileset elements to select the files to delete
  512. from the remote FTP server. Again, the filesets are relative to the remote directory, not a local
  513. directory. In fact, the <var>dir</var> attribute of the fileset is ignored completely.</p>
  514. <pre>
  515. &lt;ftp action="del"
  516. server="ftp.apache.org"
  517. userid="anonymous"
  518. password="me@myorg.com"&gt;
  519. &lt;fileset&gt;
  520. &lt;include name="**/*.tmp"/&gt;
  521. &lt;/fileset&gt;
  522. &lt;/ftp&gt;</pre>
  523. <p>Logs in to <samp>ftp.apache.org</samp> as <samp>anonymous</samp> and tries to delete
  524. all <samp>*.tmp</samp> files from the default directory for that user. If you don't have permission
  525. to delete a file, a BuildException is thrown.</p>
  526. <h3>Listing Files</h3>
  527. <pre>
  528. &lt;ftp action="list"
  529. server="ftp.apache.org"
  530. userid="anonymous"
  531. password="me@myorg.com"
  532. listing="data/ftp.listing"&gt;
  533. &lt;fileset&gt;
  534. &lt;include name="**"/&gt;
  535. &lt;/fileset&gt;
  536. &lt;/ftp&gt;</pre>
  537. <p>This provides a file listing in <samp>data/ftp.listing</samp> of all the files on the FTP server
  538. relative to the default directory of the <samp>anonymous</samp> user. The listing is in whatever
  539. format the FTP server normally lists files.</p>
  540. <h3>Creating directories</h3>
  541. <p>Note that with the <q>mkdir</q> action, the directory to create is specified using
  542. the <var>remotedir</var> attribute.</p>
  543. <pre>
  544. &lt;ftp action="mkdir"
  545. server="ftp.apache.org"
  546. userid="anonymous"
  547. password="me@myorg.com"
  548. remotedir="some/remote/dir"/&gt;</pre>
  549. <p>This creates the directory <samp>some/remote/dir</samp> beneath the default root directory. As
  550. with all other actions, the directory separator character must be correct according to the desires
  551. of the FTP server.</p>
  552. <h3>Removing directories</h3>
  553. <p>This action uses nested fileset elements to select the directories to remove from the remote FTP
  554. server. The filesets are relative to the remote directory, not a local directory.
  555. The <var>dir</var> attribute of the fileset is ignored completely. The directories to be removed
  556. must be empty, or contain only other directories that have been also selected to be removed by the
  557. filesets patterns, otherwise a BuildException will be thrown. Also, if you don't have permission to
  558. remove a directory, a BuildException is thrown.</p>
  559. <pre>
  560. &lt;ftp action="rmdir"
  561. server="ftp.apache.org"
  562. userid="anonymous"
  563. password="me@myorg.com"
  564. remotedir="/somedir" &gt;
  565. &lt;fileset&gt;
  566. &lt;include name="dira"/&gt;
  567. &lt;include name="dirb/**"/&gt;
  568. &lt;/fileset&gt;
  569. &lt;/ftp&gt;</pre>
  570. <p>Logs in to <samp>ftp.apache.org</samp> as <samp>anonymous</samp> and tries to
  571. remove <samp>/somedir/dira</samp> directory and all the directories tree starting at, and
  572. including, <samp>/somedir/dirb</samp>. When removing the <samp>/somedir/dirb</samp> tree, it will
  573. start at the leaves moving up to the root, so that when it tries to remove a directory it is sure
  574. all the directories under it are already removed. Obviously all the files in the tree must have
  575. been already deleted.</p>
  576. <p>As an example suppose you want to delete everything contained into <samp>/somedir</samp>, so
  577. invoke first the <code>&lt;ftp&gt;</code> task with <var>action</var>=<q>delete</q>, then
  578. with <var>action</var>=<q>rmdir</q> specifying in both cases <var>remotedir</var>=<q>/somedir</q>
  579. and</p>
  580. <pre>
  581. &lt;fileset&gt;
  582. &lt;include name="**"/&gt;
  583. &lt;/fileset&gt;</pre>
  584. <p>The directory specified in the <var>remotedir</var> parameter is never selected for remove, so if
  585. you need to remove it, specify its parent in <var>remotedir</var> parameter and include it in the
  586. <code>&lt;fileset&gt;</code> pattern, like <samp>somedir/**</samp>.</p>
  587. </body>
  588. </html>