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 14 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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>Warning: </b> for the get and delete actions to work properly
  29. with a Windows 2000 ftp server, it needs to be configured to generate
  30. Unix style listings, and not the default MS-DOS listing. Or someone needs to write
  31. the code to parse MS-DOS listings -any takers?
  32. <h3>Parameters</h3>
  33. <table border="1" cellpadding="2" cellspacing="0">
  34. <tr>
  35. <td valign="top"><b>Attribute</b></td>
  36. <td valign="top"><b>Description</b></td>
  37. <td align="center" valign="top"><b>Required</b></td>
  38. </tr>
  39. <tr>
  40. <td valign="top">server</td>
  41. <td valign="top">the address of the remote ftp server.</td>
  42. <td valign="top" align="center">Yes</td>
  43. </tr>
  44. <tr>
  45. <td valign="top">port</td>
  46. <td valign="top">the port number of the remote ftp server.
  47. Defaults to port 21.</td>
  48. <td valign="top" align="center">No</td>
  49. </tr>
  50. <tr>
  51. <td valign="top">userid</td>
  52. <td valign="top">the login id to use on the ftp server.</td>
  53. <td valign="top" align="center">Yes</td>
  54. </tr>
  55. <tr>
  56. <td valign="top">password</td>
  57. <td valign="top">the login password to use on the ftp server.</td>
  58. <td valign="top" align="center">Yes</td>
  59. </tr>
  60. <tr>
  61. <td valign="top">remotedir</td>
  62. <td valign="top">the directory to which to upload files on the
  63. ftp server.</td>
  64. <td valign="top" align="center">No</td>
  65. </tr>
  66. <tr>
  67. <td valign="top">action</td>
  68. <td valign="top">the ftp action to perform, defaulting to &quot;send&quot;.
  69. Currently supports &quot;put&quot;, &quot;get&quot;,
  70. &quot;del&quot;, &quot;list&quot;, &quot;chmod&quot;,
  71. &quot;mkdir&quot; and &quot;rmdir&quot;.</td>
  72. <td valign="top" align="center">No</td>
  73. </tr>
  74. <tr>
  75. <td valign="top">binary</td>
  76. <td valign="top">selects binary-mode (&quot;yes&quot;) or text-mode
  77. (&quot;no&quot;) transfers.
  78. Defaults to &quot;yes&quot;</td>
  79. <td valign="top" align="center">No</td>
  80. </tr>
  81. <tr>
  82. <td valign="top">passive</td>
  83. <td valign="top">selects passive-mode (&quot;yes&quot;) transfers.
  84. Defaults to &quot;no&quot;</td>
  85. <td valign="top" align="center">No</td>
  86. </tr>
  87. <tr>
  88. <td valign="top">verbose</td>
  89. <td valign="top">displays information on each file transferred if set
  90. to &quot;yes&quot;. Defaults to &quot;no&quot;.</td>
  91. <td valign="top" align="center">No</td>
  92. </tr>
  93. <tr>
  94. <td valign="top">depends</td>
  95. <td valign="top">transfers only new or changed files if set to
  96. &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">newer</td>
  101. <td valign="top">a synonym for <i>depends</i>.</td>
  102. <td valign="top" align="center">No</td>
  103. </tr>
  104. <tr>
  105. <td valign="top">separator</td>
  106. <td valign="top">sets the file separator used on the ftp server.
  107. Defaults to &quot;/&quot;.</td>
  108. <td valign="top" align="center">No</td>
  109. </tr>
  110. <tr>
  111. <td valign="top">umask</td>
  112. <td valign="top">sets the default file permissions for new files,
  113. unix only.</td>
  114. <td valign="top" align="center">No</td>
  115. </tr>
  116. <tr>
  117. <td valign="top">chmod</td>
  118. <td valign="top">sets or changes file permissions for new or existing files,
  119. unix only. If used with a put action, chmod will be issued for each file.</td>
  120. <td valign="top" align="center">No</td>
  121. </tr>
  122. <tr>
  123. <td valign="top">listing</td>
  124. <td valign="top">the file to write results of the &quot;list&quot; action.
  125. Required for the &quot;list&quot; action, ignored otherwise.</td>
  126. <td valign="top" align="center">No</td>
  127. </tr>
  128. <tr>
  129. <td valign="top">ignoreNoncriticalErrors</td>
  130. <td valign="top">flag which permits the task to ignore some non-fatal error
  131. codes sent by some servers during directory creation: wu-ftp in particular.
  132. Default: false</td>
  133. <td valign="top" align="center">No</td>
  134. </tr>
  135. <tr>
  136. <td valign="top">skipFailedTransfers</td>
  137. <td valign="top">flag which enables unsuccessful file put, delete
  138. and get operations to be skipped with a warning and the
  139. remainder of the files still transferred. Default: false</td>
  140. <td valign="top" align="center">No</td>
  141. </tr>
  142. <tr>
  143. <td valign="top">preservelastmodified</td>
  144. <td valign="top">Give the copied files the same last modified
  145. time as the original source files (applies to getting files only).
  146. (<em>Note</em>: Ignored on Java 1.1)</td>
  147. <td valign="top" align="center">No; defaults to false.</td>
  148. </tr>
  149. </table>
  150. <h3>Parameters specified as nested elements</h3>
  151. <h4>fileset</h4>
  152. <p>The ftp task supports any number of nested <a
  153. href="../CoreTypes/fileset.html"><code>&lt;fileset&gt;</code></a> elements to specify
  154. the files to be retrieved, or deleted, or listed, or whose mode you want to change.</p>
  155. <p>
  156. <code>followsymlinks</code> defaults to <code>false</code> for remote filesets.
  157. Remote filesets are used for all actions except put.
  158. </p>
  159. <p>
  160. Remote filesets do not support selectors.<br/>
  161. </p>
  162. <h3>Sending Files</h3>
  163. <p>The easiest way to describe how to send files is with a couple of examples:</p>
  164. <pre>
  165. &lt;ftp server=&quot;ftp.apache.org&quot;
  166. userid=&quot;anonymous&quot;
  167. password=&quot;me@myorg.com&quot;&gt;
  168. &lt;fileset dir=&quot;htdocs/manual&quot;/&gt;
  169. &lt;/ftp&gt;
  170. </pre>
  171. <p>Logs in to <code>ftp.apache.org</code> as <code>anonymous</code> and
  172. uploads all files in the <code>htdocs/manual</code> directory
  173. to the default directory for that user.</p>
  174. <pre> &lt;ftp server=&quot;ftp.apache.org&quot;
  175. remotedir=&quot;incoming&quot;
  176. userid=&quot;anonymous&quot;
  177. password=&quot;me@myorg.com&quot;
  178. depends=&quot;yes&quot;
  179. &gt;
  180. &lt;fileset dir=&quot;htdocs/manual&quot;/&gt;
  181. &lt;/ftp&gt;</pre>
  182. <p>Logs in to <code>ftp.apache.org</code> as <code>anonymous</code> and
  183. uploads all new or changed files in the <code>htdocs/manual</code> directory
  184. to the <code>incoming</code> directory relative to the default directory
  185. for <code>anonymous</code>.</p>
  186. <pre> &lt;ftp server=&quot;ftp.apache.org&quot;
  187. port=&quot;2121&quot;
  188. remotedir=&quot;/pub/incoming&quot;
  189. userid=&quot;coder&quot;
  190. password=&quot;java1&quot;
  191. depends=&quot;yes&quot;
  192. binary=&quot;no&quot;
  193. &gt;
  194. &lt;fileset dir=&quot;htdocs/manual&quot;&gt;
  195. &lt;include name=&quot;**/*.html&quot;/&gt;
  196. &lt;/fileset&gt;
  197. &lt;/ftp&gt;</pre>
  198. <p>Logs in to <code>ftp.apache.org</code> at port <code>2121</code> as
  199. <code>coder</code> with password <code>java1</code> and uploads all new or
  200. changed HTML files in the <code>htdocs/manual</code> directory to the
  201. <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>
  202. <pre> &lt;ftp server=&quot;ftp.nt.org&quot;
  203. remotedir=&quot;c:\uploads&quot;
  204. userid=&quot;coder&quot;
  205. password=&quot;java1&quot;
  206. separator=&quot;\&quot;
  207. verbose=&quot;yes&quot;</pre>
  208. <PRE>
  209. &gt;
  210. &lt;fileset dir=&quot;htdocs/manual&quot;&gt;
  211. &lt;include name=&quot;**/*.html&quot;/&gt;
  212. &lt;/fileset&gt;
  213. &lt;/ftp&gt;</PRE><p>Logs in to the Windows-based <code>ftp.nt.org</code> as
  214. <code>coder</code> with password <code>java1</code> and uploads all
  215. HTML files in the <code>htdocs/manual</code> directory to the
  216. <code>c:\uploads</code> directory. Progress messages are displayed as each
  217. file is uploaded.</p>
  218. <h3>Getting Files</h3>
  219. <p>Getting files from an FTP server works pretty much the same way as
  220. sending them does. The only difference is that the nested filesets
  221. use the remotedir attribute as the base directory for the files on the
  222. FTP server, and the dir attribute as the local directory to put the files
  223. into. The file structure from the FTP site is preserved on the local machine.</p>
  224. <pre>
  225. &lt;ftp action=&quot;get&quot;
  226. server=&quot;ftp.apache.org&quot;
  227. userid=&quot;anonymous&quot;
  228. password=&quot;me@myorg.com&quot;&gt;
  229. &lt;fileset dir=&quot;htdocs/manual&quot;&gt;
  230. &lt;include name=&quot;**/*.html&quot;/&gt;
  231. &lt;/fileset&gt;
  232. &lt;/ftp&gt;
  233. </pre>
  234. <p>Logs in to <code>ftp.apache.org</code> as <code>anonymous</code> and
  235. recursively downloads all .html files from default directory for that user
  236. into the <code>htdocs/manual</code> directory on the local machine.</p>
  237. .
  238. <h3>Deleting Files</h3>
  239. As you've probably guessed by now, you use nested fileset elements to
  240. select the files to delete from the remote FTP server. Again, the
  241. filesets are relative to the remote directory, not a local directory. In
  242. fact, the dir attribute of the fileset is ignored completely.
  243. <pre>
  244. &lt;ftp action=&quot;del&quot;
  245. server=&quot;ftp.apache.org&quot;
  246. userid=&quot;anonymous&quot;
  247. password=&quot;me@myorg.com&quot;&gt;
  248. &lt;fileset&gt;
  249. &lt;include name=&quot;**/*.tmp&quot;/&gt;
  250. &lt;/fileset&gt;
  251. &lt;/ftp&gt;
  252. </pre>
  253. <p>Logs in to <code>ftp.apache.org</code> as <code>anonymous</code> and
  254. tries to delete all *.tmp files from the default directory for that user.
  255. If you don't have permission to delete a file, a BuildException is thrown.</p>
  256. <h3>Listing Files</h3>
  257. <pre>
  258. &lt;ftp action=&quot;list&quot;
  259. server=&quot;ftp.apache.org&quot;
  260. userid=&quot;anonymous&quot;
  261. password=&quot;me@myorg.com&quot;
  262. listing=&quot;data/ftp.listing&quot;&gt;
  263. &lt;fileset&gt;
  264. &lt;include name=&quot;**&quot;/&gt;
  265. &lt;/fileset&gt;
  266. &lt;/ftp&gt;
  267. </pre>
  268. <p>This provides a file listing in <code>data/ftp.listing</code> of all the files on
  269. the FTP server relative to the default directory of the <code>anonymous</code>
  270. user. The listing is in whatever format the FTP server normally lists files.</p>
  271. <h3>Creating Directories</h3>
  272. <p>Note that with the mkdir action, the directory to create is specified using the
  273. remotedir attribute.</p>
  274. <pre>
  275. &lt;ftp action=&quot;mkdir&quot;
  276. server=&quot;ftp.apache.org&quot;
  277. userid=&quot;anonymous&quot;
  278. password=&quot;me@myorg.com&quot;
  279. remotedir=&quot;some/remote/dir&quot;/&gt;
  280. </pre>
  281. <p>This creates the directory <code>some/remote/dir</code> beneath the default root
  282. directory. As with all other actions, the directory separator character must be correct
  283. according to the desires of the FTP server.</p>
  284. <h3>Removing Directories</h3>
  285. This action uses nested fileset elements to
  286. select the directories to remove from the remote FTP server. The
  287. filesets are relative to the remote directory, not a local directory.
  288. The dir attribute of the fileset is ignored completely.
  289. The directories to be removed must be empty, or contain only
  290. other directories that have been also selected to be removed by the filesets
  291. patterns, otherwise a BuildException will be thrown.
  292. Also, if you don't have permission to remove a directory, a BuildException is
  293. thrown.
  294. <pre>
  295. &lt;ftp action=&quot;rmdir&quot;
  296. server=&quot;ftp.apache.org&quot;
  297. userid=&quot;anonymous&quot;
  298. password=&quot;me@myorg.com&quot;
  299. remotedir=&quot;/somedir&quot; &gt;
  300. &lt;fileset&gt;
  301. &lt;include name=&quot;dira&quot;/&gt;
  302. &lt;include name=&quot;dirb/**&quot;/&gt;
  303. &lt;/fileset&gt;
  304. &lt;/ftp&gt;
  305. </pre>
  306. <p>Logs in to <code>ftp.apache.org</code> as <code>anonymous</code> and
  307. tries to remove <code>/somedir/dira</code> directory and
  308. all the directories tree starting at, and including, <code>/somedir/dirb</code>.
  309. When removing the <code>/somedir/dirb</code> tree,
  310. it will start at the leaves moving up to the root, so that when
  311. it tries to remove a directory it is sure all the directories under it are
  312. already removed.
  313. Obviuosly all the files in the tree must have been already deleted.
  314. </p>
  315. <p>As an example suppose you want to delete everything contained into
  316. <code>/somedir</code>, so invoke first the <code>&lt;ftp&gt;</code> task with
  317. <code>action=&quot;delete&quot;</code>, then with
  318. <code>action=&quot;rmdir&quot;</code> specifying in both cases
  319. <code>remotedir=&quot;/somedir&quot;</code> and
  320. <pre>
  321. &lt;fileset&gt;
  322. &lt;include name=&quot;**&quot;/&gt;
  323. &lt;/fileset&gt;
  324. </pre>
  325. The directory specified in the <code>remotedir</code> parameter is never
  326. selected for remove, so if you need to remove it, specify its parent in
  327. <code>remotedir</code> parameter and include it in the
  328. <code>&lt;fileset&gt;</code> pattern, like <code>&quot;somedir/**&quot;</code>.
  329. </p>
  330. <hr>
  331. <p align="center">Copyright &copy; 2000-2002 Apache Software Foundation. All rights
  332. Reserved.</p>
  333. </body>
  334. </html>