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

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