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

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