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 26 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  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 <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>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> 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). (<strong>Note</strong>: Ignored on Java 1.1)</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 colspan="3" class="left">
  218. <p><strong>The following attributes
  219. require <a href="https://commons.apache.org/net/download_net.cgi"
  220. target="_top">jakarta-commons-net-1.4.0 or greater</a>.</strong></p>
  221. <p>Use these options when the standard options don't work, because</p>
  222. <ul>
  223. <li>the server is in a different timezone and you need timestamp dependency checking</li>
  224. <li>the default timestamp formatting doesn't match the server display and list parsing
  225. therefore fails</li>
  226. </ul>
  227. <p>If none of these is specified, the default mechanism of letting the system auto-detect the
  228. server OS type based on the FTP <code>SYST</code> command and assuming standard formatting
  229. for that OS type will be used.</p>
  230. <p>To aid in property-file-based development where a build script is configured with property
  231. files, for any of these attributes, a value of <q></q> is equivalent to not specifying it.</p>
  232. <p>Please understand that these options are incompatible with the autodetection scheme. If
  233. any of these options is specified, (other than with a value of <q></q>) a system type must be
  234. chosen and if <var>systemTypeKey</var> is not specified, UNIX will be assumed. The philosophy
  235. behind this is that these options are for setting non-standard formats, and a build-script
  236. author who knows what system he is dealing with will know what options to need to be
  237. set. Otherwise, these options should be left alone and the default autodetection scheme can be
  238. used and will work in the majority of cases.</p>
  239. </td>
  240. </tr>
  241. <tr>
  242. <td>systemTypeKey</td>
  243. <td>Specifies the type of system in use on the server. Supported values
  244. are <q>UNIX</q>, <q>VMS</q>, <q>WINDOWS</q>, <q>OS/2</q>, <q>OS/400</q>, <q>MVS</q>. If not
  245. specified, (or specified as <q></q>) and if no other <var>xxxConfig</var> attributes are
  246. specified, the autodetection mechanism based on the FTP <code>SYST</code> command will be
  247. used.<br/><em>Since Ant 1.7</em></td>
  248. <td>No, but if any of the following <var>xxxConfig</var> attributes is specified, UNIX will be
  249. assumed, even if <q></q> is specified here.
  250. </td>
  251. </tr>
  252. <tr>
  253. <td>serverTimeZoneConfig</td>
  254. <td>Specify as a
  255. Java <a href="https://docs.oracle.com/javase/8/docs/api/java/util/TimeZone.html"
  256. target="_top">TimeZone</a> identifier, (e.g. <q>GMT</q>, <q>America/Chicago</q>
  257. or <q>Asia/Jakarta</q>) the timezone used by the server for timestamps. This enables
  258. timestamp dependency checking even when the server is in a different time zone from the
  259. client. Time Zones know, also, about daylight savings time, and do not require you to
  260. calculate milliseconds of difference. If not specified, (or specified as <q></q>), the time
  261. zone of the client is assumed.<br/><em>Since Ant 1.7</em></td>
  262. <td>No</td>
  263. </tr>
  264. <tr>
  265. <td>defaultDateFormatConfig</td>
  266. <td>Specify in
  267. Java <a href="https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html"
  268. target="_top">SimpleDateFormat</a> notation, (e.g. <q>yyyy-MM-dd</q>), the date format
  269. generally used by the FTP server to parse dates. In some cases this will be the only date
  270. format used. In others, (<q>unix</q> for example) this will be used for dates older than a
  271. year old. (See <var>recentDateFormatConfig</var>). When specified as <q></q>, default value
  272. will be used.<br/><em>Since Ant 1.7</em></td>
  273. <td>No; defaults to default date format for the system type indicated
  274. by <var>systemTypeKey</var></td>
  275. </tr>
  276. <tr>
  277. <td>recentDateFormatConfig</td>
  278. <td>Specify in
  279. Java <a href="https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html"
  280. target="_top">SimpleDateFormat</a> notation, (e.g. <q>MMM dd hh:mm</q>) the date format used
  281. by the FTP server to parse dates less than a year old. If not specified (or specified
  282. as <q></q>), and if the system type indicated by the <var>systemTypeKey</var> uses a recent
  283. date format, its standard format will be used.<br/><em>Since Ant 1.7</em></td>
  284. <td>No</td>
  285. </tr>
  286. <tr>
  287. <td>serverLanguageCodeConfig</td>
  288. <td>a <a href="http://www.mathguide.de/info/tools/languagecode.html" target="_top">two-letter
  289. ISO-639 language code</a> used to specify the language used by the server to format month
  290. names. This only needs to be specified when the server uses non-numeric abbreviations for
  291. months in its date listings in a language other than English. This appears to be becoming
  292. rarer and rarer, as commonly distributed FTP servers seem increasingly to use English or
  293. all-numeric formats. Languages supported are:
  294. <ul>
  295. <li><q>en</q>&mdash;English</li>
  296. <li><q>fr</q>&mdash;French</li>
  297. <li><q>de</q>&mdash;German</li>
  298. <li><q>it</q>&mdash;Italian</li>
  299. <li><q>es</q>&mdash;Spanish</li>
  300. <li><q>pt</q>&mdash;Portuguese</li>
  301. <li><q>da</q>&mdash;Danish</li>
  302. <li><q>sv</q>&mdash;Swedish</li>
  303. <li><q>no</q>&mdash;Norwegian</li>
  304. <li><q>nl</q>&mdash;Dutch</li>
  305. <li><q>ro</q>&mdash;Romanian</li>
  306. <li><q>sq</q>&mdash;Albanian</li>
  307. <li><q>sh</q>&mdash;Serbo-Croatian</li>
  308. <li><q>sk</q>&mdash;Slovak</li>
  309. <li><q>sl</q>&mdash;Slovenian</li>
  310. </ul>
  311. If you require a language other than the above, see also the <var>shortMonthNamesConfig</var>
  312. attribute.<br/><em>Since Ant 1.7</em></td>
  313. <td>No</td>
  314. </tr>
  315. <tr>
  316. <td>shortMonthNamesConfig</td>
  317. <td>specify the month abbreviations used on the server in file timestamp dates as a
  318. pipe-delimited string for each month. For example, a set of month names used by a hypothetical
  319. Icelandic FTP server might conceivably be specified
  320. as <q>jan|feb|mar|apr|ma&iacute;|j&uacute;n|j&uacute;l|&aacute;g&uacute;|sep|okt|n&oacute;v|des</q>.
  321. This attribute exists primarily to support languages not supported by
  322. the <var>serverLanguageCode</var> attribute.<br/><em>Since Ant 1.7</em></td>
  323. <td>No</td>
  324. </tr>
  325. </table>
  326. <h3>Note about <var>remotedir</var> attribute</h3>
  327. <table>
  328. <thead>
  329. <tr>
  330. <th>Action</th>
  331. <th>meaning of <var>remotedir</var></th>
  332. <th>use of nested <var>fileset</var>(s)</th>
  333. </tr>
  334. </thead>
  335. <tbody>
  336. <tr>
  337. <td><q>send</q>/<q>put</q></td>
  338. <td>base directory to which the files are sent</td>
  339. <td>they are used normally and evaluated on the local machine</td>
  340. </tr>
  341. <tr>
  342. <td><q>recv</q>/<q>get</q></td>
  343. <td>base directory from which the files are retrieved</td>
  344. <td>the remote files located under the <var>remotedir</var> matching the include/exclude
  345. patterns of the <var>fileset</var></td>
  346. </tr>
  347. <tr>
  348. <td><q>del</q>/<q>delete</q></td>
  349. <td>base directory from which files get deleted</td>
  350. <td>the remote files located under the <var>remotedir</var> matching the include/exclude
  351. patterns of the <var>fileset</var></td>
  352. </tr>
  353. <tr>
  354. <td><q>list</q></td>
  355. <td>base directory from which files are listed</td>
  356. <td>the remote files located under the <var>remotedir</var> matching the include/exclude
  357. patterns of the <var>fileset</var></td>
  358. </tr>
  359. <tr>
  360. <td><q>mkdir</q></td>
  361. <td>directory to create</td>
  362. <td><em>not used</em></td>
  363. </tr>
  364. <tr>
  365. <td><q>chmod</q></td>
  366. <td>base directory from which the mode of files get changed</td>
  367. <td>the remote files located under the <var>remotedir</var> matching the include/exclude
  368. patterns of the <var>fileset</var></td>
  369. </tr>
  370. <tr>
  371. <td><q>rmdir</q></td>
  372. <td>base directory from which directories get removed</td>
  373. <td>the remote directories located under the <var>remotedir</var> matching the include/exclude
  374. patterns of the <var>fileset</var></td>
  375. </tr>
  376. </tbody>
  377. </table>
  378. <h3>Parameters specified as nested elements</h3>
  379. <h4>fileset</h4>
  380. <p>The <code>ftp</code> task supports any number of
  381. nested <a href="../Types/fileset.html"><code>&lt;fileset&gt;</code></a> elements to specify the
  382. files to be retrieved, or deleted, or listed, or whose mode you want to change.</p>
  383. <p>The attribute <var>followsymlinks</var> of <code>fileset</code> is supported on local
  384. (<q>put</q>) as well as remote (<q>get</q>, <q>chmod</q>, <q>delete</q>) filesets. <em>Before Ant
  385. 1.6 there was no support of symbolic links in remote filesets. In order to exclude symbolic links
  386. (preserve the behavior of Ant 1.5.x and older), you need to explicitly set <var>followsymlinks</var>
  387. to <q>false</q>.</em> On remote filesets hidden files are not checked for being symbolic links.
  388. Hidden files are currently assumed to not be symbolic links.</p>
  389. <h3>Sending files</h3>
  390. <p>The easiest way to describe how to send files is with a couple of examples:</p>
  391. <pre>
  392. &lt;ftp server="ftp.apache.org"
  393. userid="anonymous"
  394. password="me@myorg.com"&gt;
  395. &lt;fileset dir="htdocs/manual"/&gt;
  396. &lt;/ftp&gt;</pre>
  397. <p>Logs in to <samp>ftp.apache.org</samp> as <samp>anonymous</samp> and uploads all files in
  398. the <samp>htdocs/manual</samp> directory to the default directory for that user.</p>
  399. <pre>
  400. &lt;ftp server="ftp.apache.org"
  401. remotedir="incoming"
  402. userid="anonymous"
  403. password="me@myorg.com"
  404. depends="yes"&gt;
  405. &lt;fileset dir="htdocs/manual"/&gt;
  406. &lt;/ftp&gt;</pre>
  407. <p>Logs in to <samp>ftp.apache.org</samp> as <samp>anonymous</samp> and uploads all new or changed
  408. files in the <samp>htdocs/manual</samp> directory to the <samp>incoming</samp> directory relative to
  409. the default directory for <samp>anonymous</samp>.</p>
  410. <pre>
  411. &lt;ftp server="ftp.apache.org"
  412. port="2121"
  413. remotedir="/pub/incoming"
  414. userid="coder"
  415. password="java1"
  416. passive="yes"
  417. depends="yes"
  418. binary="no"&gt;
  419. &lt;fileset dir="htdocs/manual"&gt;
  420. &lt;include name="**/*.html"/&gt;
  421. &lt;/fileset&gt;
  422. &lt;/ftp&gt;</pre>
  423. <p>Logs in to <samp>ftp.apache.org</samp> at port <samp>2121</samp> as <samp>coder</samp> with
  424. password <samp>java1</samp> and uploads 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.hypothetical.india.org"
  430. port="2121"
  431. remotedir="/pub/incoming"
  432. userid="coder"
  433. password="java1"
  434. depends="yes"
  435. binary="no"
  436. systemTypeKey="Windows"
  437. serverTimeZoneConfig="India/Calcutta"&gt;
  438. &lt;fileset dir="htdocs/manual"&gt;
  439. &lt;include name="**/*.html"/&gt;
  440. &lt;/fileset&gt;
  441. &lt;/ftp&gt;</pre>
  442. <p>Logs in to a Windows server at <samp>ftp.hypothetical.india.org</samp> at port <samp>2121</samp>
  443. as <samp>coder</samp> with password <samp>java1</samp> and uploads all new or changed (accounting
  444. for timezone differences) HTML files in the <samp>htdocs/manual</samp> directory to
  445. the <samp>/pub/incoming</samp> directory. The files are transferred in text mode.</p>
  446. <pre>
  447. &lt;ftp server="ftp.nt.org"
  448. remotedir="c:\uploads"
  449. userid="coder"
  450. password="java1"
  451. separator="\"
  452. verbose="yes"&gt;
  453. &lt;fileset dir="htdocs/manual"&gt;
  454. &lt;include name="**/*.html"/&gt;
  455. &lt;/fileset&gt;
  456. &lt;/ftp&gt;</pre>
  457. <p>Logs in to the Windows-based <samp>ftp.nt.org</samp> as <samp>coder</samp> with
  458. password <samp>java1</samp> and uploads all HTML files in the <samp>htdocs/manual</samp> directory
  459. to the <samp>c:\uploads</samp> directory. Progress messages are displayed as each file is
  460. uploaded.</p>
  461. <h3>Getting files</h3>
  462. <p>Getting files from an FTP server works pretty much the same way as sending them does. The only
  463. difference is that the nested filesets use the <var>remotedir</var> attribute as the base directory
  464. for the files on the FTP server, and the <var>dir</var> attribute as the local directory to put the
  465. files into. The file structure from the FTP site is preserved on the local machine.</p>
  466. <pre>
  467. &lt;ftp action="get"
  468. server="ftp.apache.org"
  469. userid="anonymous"
  470. password="me@myorg.com"&gt;
  471. &lt;fileset dir="htdocs/manual"&gt;
  472. &lt;include name="**/*.html"/&gt;
  473. &lt;/fileset&gt;
  474. &lt;/ftp&gt;</pre>
  475. <p>Logs in to <samp>ftp.apache.org</samp> as <samp>anonymous</samp> and recursively downloads
  476. all <samp>.html</samp> files from default directory for that user into
  477. the <samp>htdocs/manual</samp> directory on the local machine.</p>
  478. <pre>
  479. &lt;ftp action="get"
  480. server="ftp.apache.org"
  481. userid="anonymous"
  482. password="me@myorg.com"
  483. systemTypeKey="UNIX"
  484. defaultDateFormatConfig="yyyy-MM-dd HH:mm"&gt;
  485. &lt;fileset dir="htdocs/manual"&gt;
  486. &lt;include name="**/*.html"/&gt;
  487. &lt;/fileset&gt;
  488. &lt;/ftp&gt;</pre>
  489. <p>If <samp>apache.org</samp> ever switches to a Unix FTP server that uses the new all-numeric
  490. format for timestamps, this version would become necessary. It would accomplish the same
  491. functionality as the previous example but would successfully handle the numeric timestamps.
  492. The <var>systemTypeKey</var> is not necessary here but helps clarify what is going on.</p>
  493. <pre>
  494. &lt;ftp action="get"
  495. server="ftp.hypthetical.fr"
  496. userid="anonymous"
  497. password="me@myorg.com"
  498. defaultDateFormatConfig="d MMM yyyy"
  499. recentDateFormatConfig="d MMM HH:mm"
  500. serverLanguageCodeConfig="fr"&gt;
  501. &lt;fileset dir="htdocs/manual"&gt;
  502. &lt;include name="**/*.html"/&gt;
  503. &lt;/fileset&gt;
  504. &lt;/ftp&gt;</pre>
  505. <p>Logs into a UNIX FTP server at <samp>ftp.hypothetical.fr</samp> which displays dates with French
  506. names in Standard European format, as <samp>anonymous</samp>, and recursively downloads
  507. all <samp>.html</samp> files from default directory for that user into
  508. the <samp>htdocs/manual</samp> directory on the local machine.</p>
  509. <h3>Deleting files</h3>
  510. <p>As you've probably guessed by now, you use nested fileset elements to select the files to delete
  511. from the remote FTP server. Again, the filesets are relative to the remote directory, not a local
  512. directory. In fact, the <var>dir</var> attribute of the fileset is ignored completely.</p>
  513. <pre>
  514. &lt;ftp action="del"
  515. server="ftp.apache.org"
  516. userid="anonymous"
  517. password="me@myorg.com"&gt;
  518. &lt;fileset&gt;
  519. &lt;include name="**/*.tmp"/&gt;
  520. &lt;/fileset&gt;
  521. &lt;/ftp&gt;</pre>
  522. <p>Logs in to <samp>ftp.apache.org</samp> as <samp>anonymous</samp> and tries to delete
  523. all <samp>*.tmp</samp> files from the default directory for that user. If you don't have permission
  524. to delete a file, a <code>BuildException</code> is thrown.</p>
  525. <h3>Listing Files</h3>
  526. <pre>
  527. &lt;ftp action="list"
  528. server="ftp.apache.org"
  529. userid="anonymous"
  530. password="me@myorg.com"
  531. listing="data/ftp.listing"&gt;
  532. &lt;fileset&gt;
  533. &lt;include name="**"/&gt;
  534. &lt;/fileset&gt;
  535. &lt;/ftp&gt;</pre>
  536. <p>This provides a file listing in <samp>data/ftp.listing</samp> of all the files on the FTP server
  537. relative to the default directory of the <samp>anonymous</samp> user. The listing is in whatever
  538. format the FTP server normally lists files.</p>
  539. <h3>Creating directories</h3>
  540. <p>Note that with the <q>mkdir</q> action, the directory to create is specified using
  541. the <var>remotedir</var> attribute.</p>
  542. <pre>
  543. &lt;ftp action="mkdir"
  544. server="ftp.apache.org"
  545. userid="anonymous"
  546. password="me@myorg.com"
  547. remotedir="some/remote/dir"/&gt;</pre>
  548. <p>This creates the directory <samp>some/remote/dir</samp> beneath the default root directory. As
  549. with all other actions, the directory separator character must be correct according to the desires
  550. of the FTP server.</p>
  551. <h3>Removing directories</h3>
  552. <p>This action uses nested fileset elements to select the directories to remove from the remote FTP
  553. server. The filesets are relative to the remote directory, not a local directory.
  554. The <var>dir</var> attribute of the fileset is ignored completely. The directories to be removed
  555. must be empty, or contain only other directories that have been also selected to be removed by the
  556. filesets patterns, otherwise a <code>BuildException</code> will be thrown. Also, if you don't have
  557. permission to remove a directory, a <code>BuildException</code> is thrown.</p>
  558. <pre>
  559. &lt;ftp action="rmdir"
  560. server="ftp.apache.org"
  561. userid="anonymous"
  562. password="me@myorg.com"
  563. remotedir="/somedir" &gt;
  564. &lt;fileset&gt;
  565. &lt;include name="dira"/&gt;
  566. &lt;include name="dirb/**"/&gt;
  567. &lt;/fileset&gt;
  568. &lt;/ftp&gt;</pre>
  569. <p>Logs in to <samp>ftp.apache.org</samp> as <samp>anonymous</samp> and tries to
  570. remove <samp>/somedir/dira</samp> directory and all the directories tree starting at, and
  571. including, <samp>/somedir/dirb</samp>. When removing the <samp>/somedir/dirb</samp> tree, it will
  572. start at the leaves moving up to the root, so that when it tries to remove a directory it is sure
  573. all the directories under it are already removed. Obviously all the files in the tree must have
  574. been already deleted.</p>
  575. <p>As an example suppose you want to delete everything contained into <samp>/somedir</samp>, so
  576. invoke first the <code>&lt;ftp&gt;</code> task with <var>action</var>=<q>delete</q>, then
  577. with <var>action</var>=<q>rmdir</q> specifying in both cases <var>remotedir</var>=<q>/somedir</q>
  578. and</p>
  579. <pre>
  580. &lt;fileset&gt;
  581. &lt;include name="**"/&gt;
  582. &lt;/fileset&gt;</pre>
  583. <p>The directory specified in the <var>remotedir</var> parameter is never selected for remove, so if
  584. you need to remove it, specify its parent in <var>remotedir</var> parameter and include it in the
  585. <code>&lt;fileset&gt;</code> pattern, like <samp>somedir/**</samp>.</p>
  586. </body>
  587. </html>