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

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