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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Language" content="en-us">
  4. <title>FTP Task</title>
  5. </head>
  6. <body>
  7. <h2><a name="ftp">FTP</a></h2>
  8. <h3>Description</h3>
  9. <p>The ftp task implements a basic FTP client that can send, receive,
  10. list, delete files, and create directories. See below for descriptions and examples of how
  11. to perform each task.</p>
  12. <p><b>Note:</b> This task depends on external libraries not included in the Ant distribution.
  13. See <a href="../install.html#librarydependencies">Library Dependencies</a> for more information.</p>
  14. <p>The ftp task makes no attempt to determine what file system syntax is
  15. required by the remote server, and defaults to Unix standards.
  16. <i>remotedir</i> must be specified in the exact syntax required by the ftp
  17. server. If the usual Unix conventions are not supported by the server,
  18. <i>separator</i> can be used to set the file separator that should be used
  19. instead.</p>
  20. <p>See the section on <a href="../dirtasks.html#directorybasedtasks">directory based
  21. tasks</a>, on how the inclusion/exclusion of files works, and how to
  22. write patterns.</p>
  23. <p>
  24. This task does not currently use the proxy information set by the
  25. <a href="setproxy.html">&lt;setproxy&gt;</a> task, and cannot go through
  26. a firewall via socks.
  27. <p>
  28. <b>Use of the FTP task with Microsoft FTP servers
  29. </b>
  30. <p>
  31. To use the FTP task with Microsoft FTP servers,
  32. you need CVS HEAD of commons-net and jakarta-oro after 2004-02-01
  33. or a release of commons-net after 1.1.0 and jakarta-oro after 2.0.8.
  34. </p>
  35. <b>Warning: </b> there have been problems reported concerning the ftp get with newer attribute.
  36. Problems might be due to format of ls -l differing from what is expected by commons-net,
  37. for instance due to specificities of langage used by the ftp server in the directory listing.
  38. If you encounter such a problem, please send an email including a sample directory listing
  39. coming from your ftp server (ls -l on the ftp prompt).
  40. <h3>Parameters</h3>
  41. <table border="1" cellpadding="2" cellspacing="0">
  42. <tr>
  43. <td valign="top"><b>Attribute</b></td>
  44. <td valign="top"><b>Description</b></td>
  45. <td align="center" valign="top"><b>Required</b></td>
  46. </tr>
  47. <tr>
  48. <td valign="top">server</td>
  49. <td valign="top">the address of the remote ftp server.</td>
  50. <td valign="top" align="center">Yes</td>
  51. </tr>
  52. <tr>
  53. <td valign="top">port</td>
  54. <td valign="top">the port number of the remote ftp server.
  55. Defaults to port 21.</td>
  56. <td valign="top" align="center">No</td>
  57. </tr>
  58. <tr>
  59. <td valign="top">userid</td>
  60. <td valign="top">the login id to use on the ftp server.</td>
  61. <td valign="top" align="center">Yes</td>
  62. </tr>
  63. <tr>
  64. <td valign="top">password</td>
  65. <td valign="top">the login password to use on the ftp server.</td>
  66. <td valign="top" align="center">Yes</td>
  67. </tr>
  68. <tr>
  69. <td valign="top">remotedir</td>
  70. <td valign="top">remote directory on the
  71. ftp server
  72. see table below for detailed usage
  73. </td>
  74. <td valign="top" align="center">No</td>
  75. </tr>
  76. <tr>
  77. <td valign="top">action</td>
  78. <td valign="top">the ftp action to perform, defaulting to &quot;send&quot;.
  79. Currently supports &quot;put&quot;, &quot;get&quot;,
  80. &quot;del&quot;, &quot;list&quot;, &quot;chmod&quot;,
  81. &quot;mkdir&quot; and &quot;rmdir&quot;.</td>
  82. <td valign="top" align="center">No</td>
  83. </tr>
  84. <tr>
  85. <td valign="top">binary</td>
  86. <td valign="top">selects binary-mode (&quot;yes&quot;) or text-mode
  87. (&quot;no&quot;) transfers.
  88. Defaults to &quot;yes&quot;</td>
  89. <td valign="top" align="center">No</td>
  90. </tr>
  91. <tr>
  92. <td valign="top">passive</td>
  93. <td valign="top">selects passive-mode (&quot;yes&quot;) transfers.
  94. Defaults to &quot;no&quot;</td>
  95. <td valign="top" align="center">No</td>
  96. </tr>
  97. <tr>
  98. <td valign="top">verbose</td>
  99. <td valign="top">displays information on each file transferred if set
  100. to &quot;yes&quot;. Defaults to &quot;no&quot;.</td>
  101. <td valign="top" align="center">No</td>
  102. </tr>
  103. <tr>
  104. <td valign="top">depends</td>
  105. <td valign="top">transfers only new or changed files if set to
  106. &quot;yes&quot;. Defaults to &quot;no&quot;.</td>
  107. <td valign="top" align="center">No</td>
  108. </tr>
  109. <tr>
  110. <td valign="top">newer</td>
  111. <td valign="top">a synonym for <i>depends</i>.
  112. see timediffauto and timediffmillis</td>
  113. <td valign="top" align="center">No</td>
  114. </tr>
  115. <tr>
  116. <td valign="top">timediffauto</td>
  117. <td valign="top">set to <code>&quot;true&quot;</code>
  118. to make ant calculate the time difference between client and server.<br/>
  119. <em>requires write access in the remote directory</em><br/>
  120. Since ant 1.6</td>
  121. <td valign="top" align="center">No</td>
  122. </tr>
  123. <tr>
  124. <td valign="top">timediffmillis</td>
  125. <td valign="top">number of milliseconds to add to the time on the remote machine
  126. to get the time on the local machine.<br/>
  127. Since ant 1.6
  128. </td>
  129. <td valign="top" align="center">No</td>
  130. </tr>
  131. <tr>
  132. <td valign="top">separator</td>
  133. <td valign="top">sets the file separator used on the ftp server.
  134. Defaults to &quot;/&quot;.</td>
  135. <td valign="top" align="center">No</td>
  136. </tr>
  137. <tr>
  138. <td valign="top">umask</td>
  139. <td valign="top">sets the default file permissions for new files,
  140. unix only.</td>
  141. <td valign="top" align="center">No</td>
  142. </tr>
  143. <tr>
  144. <td valign="top">chmod</td>
  145. <td valign="top">sets or changes file permissions for new or existing files,
  146. unix only. If used with a put action, chmod will be issued for each file.</td>
  147. <td valign="top" align="center">No</td>
  148. </tr>
  149. <tr>
  150. <td valign="top">listing</td>
  151. <td valign="top">the file to write results of the &quot;list&quot; action.
  152. Required for the &quot;list&quot; action, ignored otherwise.</td>
  153. <td valign="top" align="center">No</td>
  154. </tr>
  155. <tr>
  156. <td valign="top">ignoreNoncriticalErrors</td>
  157. <td valign="top">flag which permits the task to ignore some non-fatal error
  158. codes sent by some servers during directory creation: wu-ftp in particular.
  159. Default: false</td>
  160. <td valign="top" align="center">No</td>
  161. </tr>
  162. <tr>
  163. <td valign="top">skipFailedTransfers</td>
  164. <td valign="top">flag which enables unsuccessful file put, delete
  165. and get operations to be skipped with a warning and the
  166. remainder of the files still transferred. Default: false</td>
  167. <td valign="top" align="center">No</td>
  168. </tr>
  169. <tr>
  170. <td valign="top">preservelastmodified</td>
  171. <td valign="top">Give the copied files the same last modified
  172. time as the original source files (applies to getting files only).
  173. (<em>Note</em>: Ignored on Java 1.1)</td>
  174. <td valign="top" align="center">No; defaults to false.</td>
  175. </tr>
  176. </table>
  177. <h3>Note about remotedir attribute</h3>
  178. <table border="1" cellpadding="2" cellspacing="0"
  179. >
  180. <tbody>
  181. <tr>
  182. <td style="vertical-align: top;" width="20%">Action<br>
  183. </td>
  184. <td style="vertical-align: top;" width="40%">meaning of <code>remotedir</code><br>
  185. </td>
  186. <td style="vertical-align: top;">use of nested <code>fileset</code>
  187. (s)<br>
  188. </td>
  189. </tr>
  190. <tr>
  191. <td style="vertical-align: top;" width="20%">send/put<br>
  192. </td>
  193. <td style="vertical-align: top;" width="40%">base directory to
  194. which the files are sent<br>
  195. </td>
  196. <td style="vertical-align: top;">they are used normally and
  197. evaluated on the local machine<br>
  198. </td>
  199. </tr>
  200. <tr>
  201. <td style="vertical-align: top;" width="20%">recv/get<br>
  202. </td>
  203. <td style="vertical-align: top;" width="40%">base directory from
  204. which the files are retrieved<br>
  205. </td>
  206. <td style="vertical-align: top;">the remote files located under
  207. the <code>remotedir </code>matching the include/exclude patterns of
  208. the <code>fileset&nbsp;</code></td>
  209. </tr>
  210. <tr>
  211. <td style="vertical-align: top;" width="20%">del/delete<br>
  212. </td>
  213. <td style="vertical-align: top;" width="40%">base directory from
  214. which files get deleted<br>
  215. </td>
  216. <td style="vertical-align: top;">the remote files located under
  217. the <code>remotedir </code>matching the include/exclude patterns of
  218. the <code>fileset <br>
  219. </code></td>
  220. </tr>
  221. <tr>
  222. <td style="vertical-align: top;" width="20%">list<br>
  223. </td>
  224. <td style="vertical-align: top;" width="40%">base directory from
  225. which files are listed<br>
  226. </td>
  227. <td style="vertical-align: top;">the remote files located under
  228. the <code>remotedir </code>matching the include/exclude patterns of
  229. the <code>fileset <br>
  230. </code></td>
  231. </tr>
  232. <tr>
  233. <td style="vertical-align: top;" width="20%">mkdir</td>
  234. <td style="vertical-align: top;" width="40%">directory to create<br>
  235. </td>
  236. <td style="vertical-align: top;">not used<br>
  237. </td>
  238. </tr>
  239. <tr>
  240. <td style="vertical-align: top;" width="20%">chmod</td>
  241. <td style="vertical-align: top;" width="40%">base directory from
  242. which the mode of files get changed<br>
  243. </td>
  244. <td style="vertical-align: top;">the remote files located under
  245. the <code>remotedir </code>matching the include/exclude patterns of
  246. the <code>fileset <br>
  247. </code></td>
  248. </tr>
  249. <tr>
  250. <td style="vertical-align: top;" width="20%">rmdir<br>
  251. </td>
  252. <td style="vertical-align: top;" width="40%">base directory from
  253. which directories get removed<br>
  254. </td>
  255. <td style="vertical-align: top;">the remote directories located
  256. under the <code>remotedir </code>matching the include/exclude
  257. patterns of the <code>fileset <br>
  258. </code></td>
  259. </tr>
  260. </tbody>
  261. </table><h3>Parameters specified as nested elements</h3>
  262. <h4>fileset</h4>
  263. <p>The ftp task supports any number of nested <a
  264. href="../CoreTypes/fileset.html"><code>&lt;fileset&gt;</code></a> elements to specify
  265. the files to be retrieved, or deleted, or listed, or whose mode you want to change.</p>
  266. <p>
  267. The attribute <code>followsymlinks</code> of <code>fileset</code> is fully supported on
  268. local (put) as well as remote (get, chmod, delete) filesets.
  269. <em>Before ant 1.6 there was no support of symbolic links in remote filesets.
  270. In order to exclude symbolic links (preserve the behavior of ant 1.5.x and older),
  271. you need to explicitly set <code>followsymlinks</code> to <code>false</code>.</em>
  272. </p>
  273. <p>
  274. Remote filesets do not support selectors.<br/>
  275. </p>
  276. <h3>Sending Files</h3>
  277. <p>The easiest way to describe how to send files is with a couple of examples:</p>
  278. <pre>
  279. &lt;ftp server=&quot;ftp.apache.org&quot;
  280. userid=&quot;anonymous&quot;
  281. password=&quot;me@myorg.com&quot;&gt;
  282. &lt;fileset dir=&quot;htdocs/manual&quot;/&gt;
  283. &lt;/ftp&gt;
  284. </pre>
  285. <p>Logs in to <code>ftp.apache.org</code> as <code>anonymous</code> and
  286. uploads all files in the <code>htdocs/manual</code> directory
  287. to the default directory for that user.</p>
  288. <pre> &lt;ftp server=&quot;ftp.apache.org&quot;
  289. remotedir=&quot;incoming&quot;
  290. userid=&quot;anonymous&quot;
  291. password=&quot;me@myorg.com&quot;
  292. depends=&quot;yes&quot;
  293. &gt;
  294. &lt;fileset dir=&quot;htdocs/manual&quot;/&gt;
  295. &lt;/ftp&gt;</pre>
  296. <p>Logs in to <code>ftp.apache.org</code> as <code>anonymous</code> and
  297. uploads all new or changed files in the <code>htdocs/manual</code> directory
  298. to the <code>incoming</code> directory relative to the default directory
  299. for <code>anonymous</code>.</p>
  300. <pre> &lt;ftp server=&quot;ftp.apache.org&quot;
  301. port=&quot;2121&quot;
  302. remotedir=&quot;/pub/incoming&quot;
  303. userid=&quot;coder&quot;
  304. password=&quot;java1&quot;
  305. depends=&quot;yes&quot;
  306. binary=&quot;no&quot;
  307. &gt;
  308. &lt;fileset dir=&quot;htdocs/manual&quot;&gt;
  309. &lt;include name=&quot;**/*.html&quot;/&gt;
  310. &lt;/fileset&gt;
  311. &lt;/ftp&gt;</pre>
  312. <p>Logs in to <code>ftp.apache.org</code> at port <code>2121</code> as
  313. <code>coder</code> with password <code>java1</code> and uploads all new or
  314. changed HTML files in the <code>htdocs/manual</code> directory to the
  315. <code>/pub/incoming</code> directory. The files are transferred in text mode. Passive mode has been switched on to send files from behind a firewall.</p>
  316. <pre> &lt;ftp server=&quot;ftp.nt.org&quot;
  317. remotedir=&quot;c:\uploads&quot;
  318. userid=&quot;coder&quot;
  319. password=&quot;java1&quot;
  320. separator=&quot;\&quot;
  321. verbose=&quot;yes&quot;</pre>
  322. <PRE>
  323. &gt;
  324. &lt;fileset dir=&quot;htdocs/manual&quot;&gt;
  325. &lt;include name=&quot;**/*.html&quot;/&gt;
  326. &lt;/fileset&gt;
  327. &lt;/ftp&gt;</PRE><p>Logs in to the Windows-based <code>ftp.nt.org</code> as
  328. <code>coder</code> with password <code>java1</code> and uploads all
  329. HTML files in the <code>htdocs/manual</code> directory to the
  330. <code>c:\uploads</code> directory. Progress messages are displayed as each
  331. file is uploaded.</p>
  332. <h3>Getting Files</h3>
  333. <p>Getting files from an FTP server works pretty much the same way as
  334. sending them does. The only difference is that the nested filesets
  335. use the remotedir attribute as the base directory for the files on the
  336. FTP server, and the dir attribute as the local directory to put the files
  337. into. The file structure from the FTP site is preserved on the local machine.</p>
  338. <pre>
  339. &lt;ftp action=&quot;get&quot;
  340. server=&quot;ftp.apache.org&quot;
  341. userid=&quot;anonymous&quot;
  342. password=&quot;me@myorg.com&quot;&gt;
  343. &lt;fileset dir=&quot;htdocs/manual&quot;&gt;
  344. &lt;include name=&quot;**/*.html&quot;/&gt;
  345. &lt;/fileset&gt;
  346. &lt;/ftp&gt;
  347. </pre>
  348. <p>Logs in to <code>ftp.apache.org</code> as <code>anonymous</code> and
  349. recursively downloads all .html files from default directory for that user
  350. into the <code>htdocs/manual</code> directory on the local machine.</p>
  351. .
  352. <h3>Deleting Files</h3>
  353. As you've probably guessed by now, you use nested fileset elements to
  354. select the files to delete from the remote FTP server. Again, the
  355. filesets are relative to the remote directory, not a local directory. In
  356. fact, the dir attribute of the fileset is ignored completely.
  357. <pre>
  358. &lt;ftp action=&quot;del&quot;
  359. server=&quot;ftp.apache.org&quot;
  360. userid=&quot;anonymous&quot;
  361. password=&quot;me@myorg.com&quot;&gt;
  362. &lt;fileset&gt;
  363. &lt;include name=&quot;**/*.tmp&quot;/&gt;
  364. &lt;/fileset&gt;
  365. &lt;/ftp&gt;
  366. </pre>
  367. <p>Logs in to <code>ftp.apache.org</code> as <code>anonymous</code> and
  368. tries to delete all *.tmp files from the default directory for that user.
  369. If you don't have permission to delete a file, a BuildException is thrown.</p>
  370. <h3>Listing Files</h3>
  371. <pre>
  372. &lt;ftp action=&quot;list&quot;
  373. server=&quot;ftp.apache.org&quot;
  374. userid=&quot;anonymous&quot;
  375. password=&quot;me@myorg.com&quot;
  376. listing=&quot;data/ftp.listing&quot;&gt;
  377. &lt;fileset&gt;
  378. &lt;include name=&quot;**&quot;/&gt;
  379. &lt;/fileset&gt;
  380. &lt;/ftp&gt;
  381. </pre>
  382. <p>This provides a file listing in <code>data/ftp.listing</code> of all the files on
  383. the FTP server relative to the default directory of the <code>anonymous</code>
  384. user. The listing is in whatever format the FTP server normally lists files.</p>
  385. <h3>Creating Directories</h3>
  386. <p>Note that with the mkdir action, the directory to create is specified using the
  387. remotedir attribute.</p>
  388. <pre>
  389. &lt;ftp action=&quot;mkdir&quot;
  390. server=&quot;ftp.apache.org&quot;
  391. userid=&quot;anonymous&quot;
  392. password=&quot;me@myorg.com&quot;
  393. remotedir=&quot;some/remote/dir&quot;/&gt;
  394. </pre>
  395. <p>This creates the directory <code>some/remote/dir</code> beneath the default root
  396. directory. As with all other actions, the directory separator character must be correct
  397. according to the desires of the FTP server.</p>
  398. <h3>Removing Directories</h3>
  399. This action uses nested fileset elements to
  400. select the directories to remove from the remote FTP server. The
  401. filesets are relative to the remote directory, not a local directory.
  402. The dir attribute of the fileset is ignored completely.
  403. The directories to be removed must be empty, or contain only
  404. other directories that have been also selected to be removed by the filesets
  405. patterns, otherwise a BuildException will be thrown.
  406. Also, if you don't have permission to remove a directory, a BuildException is
  407. thrown.
  408. <pre>
  409. &lt;ftp action=&quot;rmdir&quot;
  410. server=&quot;ftp.apache.org&quot;
  411. userid=&quot;anonymous&quot;
  412. password=&quot;me@myorg.com&quot;
  413. remotedir=&quot;/somedir&quot; &gt;
  414. &lt;fileset&gt;
  415. &lt;include name=&quot;dira&quot;/&gt;
  416. &lt;include name=&quot;dirb/**&quot;/&gt;
  417. &lt;/fileset&gt;
  418. &lt;/ftp&gt;
  419. </pre>
  420. <p>Logs in to <code>ftp.apache.org</code> as <code>anonymous</code> and
  421. tries to remove <code>/somedir/dira</code> directory and
  422. all the directories tree starting at, and including, <code>/somedir/dirb</code>.
  423. When removing the <code>/somedir/dirb</code> tree,
  424. it will start at the leaves moving up to the root, so that when
  425. it tries to remove a directory it is sure all the directories under it are
  426. already removed.
  427. Obviuosly all the files in the tree must have been already deleted.
  428. </p>
  429. <p>As an example suppose you want to delete everything contained into
  430. <code>/somedir</code>, so invoke first the <code>&lt;ftp&gt;</code> task with
  431. <code>action=&quot;delete&quot;</code>, then with
  432. <code>action=&quot;rmdir&quot;</code> specifying in both cases
  433. <code>remotedir=&quot;/somedir&quot;</code> and
  434. <pre>
  435. &lt;fileset&gt;
  436. &lt;include name=&quot;**&quot;/&gt;
  437. &lt;/fileset&gt;
  438. </pre>
  439. The directory specified in the <code>remotedir</code> parameter is never
  440. selected for remove, so if you need to remove it, specify its parent in
  441. <code>remotedir</code> parameter and include it in the
  442. <code>&lt;fileset&gt;</code> pattern, like <code>&quot;somedir/**&quot;</code>.
  443. </p>
  444. <hr>
  445. <p align="center">Copyright &copy; 2000-2004 The Apache Software Foundation. All rights
  446. Reserved.</p>
  447. </body>
  448. </html>