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

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