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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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>Sending Files</h3>
  151. <p>The easiest way to describe how to send files is with a couple of examples:</p>
  152. <pre>
  153. &lt;ftp server=&quot;ftp.apache.org&quot;
  154. userid=&quot;anonymous&quot;
  155. password=&quot;me@myorg.com&quot;&gt;
  156. &lt;fileset dir=&quot;htdocs/manual&quot;/&gt;
  157. &lt;/ftp&gt;
  158. </pre>
  159. <p>Logs in to <code>ftp.apache.org</code> as <code>anonymous</code> and
  160. uploads all files in the <code>htdocs/manual</code> directory
  161. to the default directory for that user.</p>
  162. <pre> &lt;ftp server=&quot;ftp.apache.org&quot;
  163. remotedir=&quot;incoming&quot;
  164. userid=&quot;anonymous&quot;
  165. password=&quot;me@myorg.com&quot;
  166. depends=&quot;yes&quot;
  167. &gt;
  168. &lt;fileset dir=&quot;htdocs/manual&quot;/&gt;
  169. &lt;/ftp&gt;</pre>
  170. <p>Logs in to <code>ftp.apache.org</code> as <code>anonymous</code> and
  171. uploads all new or changed files in the <code>htdocs/manual</code> directory
  172. to the <code>incoming</code> directory relative to the default directory
  173. for <code>anonymous</code>.</p>
  174. <pre> &lt;ftp server=&quot;ftp.apache.org&quot;
  175. port=&quot;2121&quot;
  176. remotedir=&quot;/pub/incoming&quot;
  177. userid=&quot;coder&quot;
  178. password=&quot;java1&quot;
  179. depends=&quot;yes&quot;
  180. binary=&quot;no&quot;
  181. &gt;
  182. &lt;fileset dir=&quot;htdocs/manual&quot;&gt;
  183. &lt;include name=&quot;**/*.html&quot;/&gt;
  184. &lt;/fileset&gt;
  185. &lt;/ftp&gt;</pre>
  186. <p>Logs in to <code>ftp.apache.org</code> at port <code>2121</code> as
  187. <code>coder</code> with password <code>java1</code> and uploads all new or
  188. changed HTML files in the <code>htdocs/manual</code> directory to the
  189. <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>
  190. <pre> &lt;ftp server=&quot;ftp.nt.org&quot;
  191. remotedir=&quot;c:\uploads&quot;
  192. userid=&quot;coder&quot;
  193. password=&quot;java1&quot;
  194. separator=&quot;\&quot;
  195. verbose=&quot;yes&quot;</pre>
  196. <PRE>
  197. &gt;
  198. &lt;fileset dir=&quot;htdocs/manual&quot;&gt;
  199. &lt;include name=&quot;**/*.html&quot;/&gt;
  200. &lt;/fileset&gt;
  201. &lt;/ftp&gt;</PRE><p>Logs in to the Windows-based <code>ftp.nt.org</code> as
  202. <code>coder</code> with password <code>java1</code> and uploads all
  203. HTML files in the <code>htdocs/manual</code> directory to the
  204. <code>c:\uploads</code> directory. Progress messages are displayed as each
  205. file is uploaded.</p>
  206. <h3>Getting Files</h3>
  207. <p>Getting files from an FTP server works pretty much the same way as
  208. sending them does. The only difference is that the nested filesets
  209. use the remotedir attribute as the base directory for the files on the
  210. FTP server, and the dir attribute as the local directory to put the files
  211. into. The file structure from the FTP site is preserved on the local machine.</p>
  212. <pre>
  213. &lt;ftp action=&quot;get&quot;
  214. server=&quot;ftp.apache.org&quot;
  215. userid=&quot;anonymous&quot;
  216. password=&quot;me@myorg.com&quot;&gt;
  217. &lt;fileset dir=&quot;htdocs/manual&quot;&gt;
  218. &lt;include name=&quot;**/*.html&quot;/&gt;
  219. &lt;/fileset&gt;
  220. &lt;/ftp&gt;
  221. </pre>
  222. <p>Logs in to <code>ftp.apache.org</code> as <code>anonymous</code> and
  223. recursively downloads all .html files from default directory for that user
  224. into the <code>htdocs/manual</code> directory on the local machine.</p>
  225. .
  226. <h3>Deleting Files</h3>
  227. As you've probably guessed by now, you use nested fileset elements to
  228. select the files to delete from the remote FTP server. Again, the
  229. filesets are relative to the remote directory, not a local directory. In
  230. fact, the dir attribute of the fileset is ignored completely.
  231. <pre>
  232. &lt;ftp action=&quot;del&quot;
  233. server=&quot;ftp.apache.org&quot;
  234. userid=&quot;anonymous&quot;
  235. password=&quot;me@myorg.com&quot;&gt;
  236. &lt;fileset&gt;
  237. &lt;include name=&quot;**/*.tmp&quot;/&gt;
  238. &lt;/fileset&gt;
  239. &lt;/ftp&gt;
  240. </pre>
  241. <p>Logs in to <code>ftp.apache.org</code> as <code>anonymous</code> and
  242. tries to delete all *.tmp files from the default directory for that user.
  243. If you don't have permission to delete a file, a BuildException is thrown.</p>
  244. <h3>Listing Files</h3>
  245. <pre>
  246. &lt;ftp action=&quot;list&quot;
  247. server=&quot;ftp.apache.org&quot;
  248. userid=&quot;anonymous&quot;
  249. password=&quot;me@myorg.com&quot;
  250. listing=&quot;data/ftp.listing&quot;&gt;
  251. &lt;fileset&gt;
  252. &lt;include name=&quot;**&quot;/&gt;
  253. &lt;/fileset&gt;
  254. &lt;/ftp&gt;
  255. </pre>
  256. <p>This provides a file listing in <code>data/ftp.listing</code> of all the files on
  257. the FTP server relative to the default directory of the <code>anonymous</code>
  258. user. The listing is in whatever format the FTP server normally lists files.</p>
  259. <h3>Creating Directories</h3>
  260. <p>Note that with the mkdir action, the directory to create is specified using the
  261. remotedir attribute.</p>
  262. <pre>
  263. &lt;ftp action=&quot;mkdir&quot;
  264. server=&quot;ftp.apache.org&quot;
  265. userid=&quot;anonymous&quot;
  266. password=&quot;me@myorg.com&quot;
  267. remotedir=&quot;some/remote/dir&quot;/&gt;
  268. </pre>
  269. <p>This creates the directory <code>some/remote/dir</code> beneath the default root
  270. directory. As with all other actions, the directory separator character must be correct
  271. according to the desires of the FTP server.</p>
  272. <h3>Removing Directories</h3>
  273. This action uses nested fileset elements to
  274. select the directories to remove from the remote FTP server. The
  275. filesets are relative to the remote directory, not a local directory.
  276. The dir attribute of the fileset is ignored completely.
  277. The directories to be removed must be empty, or contain only
  278. other directories that have been also selected to be removed by the filesets
  279. patterns, otherwise a BuildException will be thrown.
  280. Also, if you don't have permission to remove a directory, a BuildException is
  281. thrown.
  282. <pre>
  283. &lt;ftp action=&quot;rmdir&quot;
  284. server=&quot;ftp.apache.org&quot;
  285. userid=&quot;anonymous&quot;
  286. password=&quot;me@myorg.com&quot;
  287. remotedir=&quot;/somedir&quot; &gt;
  288. &lt;fileset&gt;
  289. &lt;include name=&quot;dira&quot;/&gt;
  290. &lt;include name=&quot;dirb/**&quot;/&gt;
  291. &lt;/fileset&gt;
  292. &lt;/ftp&gt;
  293. </pre>
  294. <p>Logs in to <code>ftp.apache.org</code> as <code>anonymous</code> and
  295. tries to remove <code>/somedir/dira</code> directory and
  296. all the directories tree starting at, and including, <code>/somedir/dirb</code>.
  297. When removing the <code>/somedir/dirb</code> tree,
  298. it will start at the leaves moving up to the root, so that when
  299. it tries to remove a directory it is sure all the directories under it are
  300. already removed.
  301. Obviuosly all the files in the tree must have been already deleted.
  302. </p>
  303. <p>As an example suppose you want to delete everything contained into
  304. <code>/somedir</code>, so invoke first the <code>&lt;ftp&gt;</code> task with
  305. <code>action=&quot;delete&quot;</code>, then with
  306. <code>action=&quot;rmdir&quot;</code> specifying in both cases
  307. <code>remotedir=&quot;/somedir&quot;</code> and
  308. <pre>
  309. &lt;fileset&gt;
  310. &lt;include name=&quot;**&quot;/&gt;
  311. &lt;/fileset&gt;
  312. </pre>
  313. The directory specified in the <code>remotedir</code> parameter is never
  314. selected for remove, so if you need to remove it, specify its parent in
  315. <code>remotedir</code> parameter and include it in the
  316. <code>&lt;fileset&gt;</code> pattern, like <code>&quot;somedir/**&quot;</code>.
  317. </p>
  318. <hr>
  319. <p align="center">Copyright &copy; 2000-2002 Apache Software Foundation. All rights
  320. Reserved.</p>
  321. </body>
  322. </html>