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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Language" content="en-us">
  4. <title>Ant User Manual</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. <h3>Parameters</h3>
  24. <table border="1" cellpadding="2" cellspacing="0">
  25. <tr>
  26. <td valign="top"><b>Attribute</b></td>
  27. <td valign="top"><b>Description</b></td>
  28. <td align="center" valign="top"><b>Required</b></td>
  29. </tr>
  30. <tr>
  31. <td valign="top">server</td>
  32. <td valign="top">the address of the remote ftp server.</td>
  33. <td valign="top" align="center">Yes</td>
  34. </tr>
  35. <tr>
  36. <td valign="top">port</td>
  37. <td valign="top">the port number of the remote ftp server.
  38. Defaults to port 21.</td>
  39. <td valign="top" align="center">No</td>
  40. </tr>
  41. <tr>
  42. <td valign="top">userid</td>
  43. <td valign="top">the login id to use on the ftp server.</td>
  44. <td valign="top" align="center">Yes</td>
  45. </tr>
  46. <tr>
  47. <td valign="top">password</td>
  48. <td valign="top">the login password to use on the ftp server.</td>
  49. <td valign="top" align="center">Yes</td>
  50. </tr>
  51. <tr>
  52. <td valign="top">remotedir</td>
  53. <td valign="top">the directory to which to upload files on the
  54. ftp server.</td>
  55. <td valign="top" align="center">No</td>
  56. </tr>
  57. <tr>
  58. <td valign="top">action</td>
  59. <td valign="top">the ftp action to perform, defaulting to &quot;send&quot;.
  60. Currently supports &quot;put&quot;, &quot;get&quot;,
  61. &quot;del&quot;, &quot;list&quot; and &quot;mkdir&quot;.</td>
  62. <td valign="top" align="center">No</td>
  63. </tr>
  64. <tr>
  65. <td valign="top">binary</td>
  66. <td valign="top">selects binary-mode (&quot;yes&quot;) or text-mode
  67. (&quot;no&quot;) transfers.
  68. Defaults to &quot;yes&quot;</td>
  69. <td valign="top" align="center">No</td>
  70. </tr>
  71. <tr>
  72. <td valign="top">passive</td>
  73. <td valign="top">selects passive-mode (&quot;yes&quot;) transfers.
  74. Defaults to &quot;no&quot;</td>
  75. <td valign="top" align="center">No</td>
  76. </tr>
  77. <tr>
  78. <td valign="top">verbose</td>
  79. <td valign="top">displays information on each file transferred if set
  80. to &quot;yes&quot;. Defaults to &quot;no&quot;.</td>
  81. <td valign="top" align="center">No</td>
  82. </tr>
  83. <tr>
  84. <td valign="top">depends</td>
  85. <td valign="top">transfers only new or changed files if set to
  86. &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">newer</td>
  91. <td valign="top">a synonym for <i>depends</i>.</td>
  92. <td valign="top" align="center">No</td>
  93. </tr>
  94. <tr>
  95. <td valign="top">separator</td>
  96. <td valign="top">sets the file separator used on the ftp server.
  97. Defaults to &quot;/&quot;.</td>
  98. <td valign="top" align="center">No</td>
  99. </tr>
  100. <tr>
  101. <td valign="top">listing</td>
  102. <td valign="top">the file to write results of the &quot;list&quot; action.
  103. Required for the &quot;list&quot; action, ignored otherwise.</td>
  104. <td valign="top" align="center">No</td>
  105. </tr>
  106. <tr>
  107. <td valign="top">ignoreNoncriticalErrors</td>
  108. <td valign="top">flag which permits the task to ignore some non-fatal error
  109. codes sent by some servers during directory creation: wu-ftp in particular.
  110. Default: false</td>
  111. <td valign="top" align="center">No</td>
  112. </tr>
  113. <tr>
  114. <td valign="top">skipFailedTransfers</td>
  115. <td valign="top">flag which enables unsuccessful file put, delete
  116. and get operations to be skipped with a warning and the
  117. remainder of the files still transferred. Default: false</td>
  118. <td valign="top" align="center">No</td>
  119. </tr>
  120. </table>
  121. <h3>Sending Files</h3>
  122. <p>The easiest way to describe how to send files is with a couple of examples:</p>
  123. <pre>
  124. &lt;ftp server=&quot;ftp.apache.org&quot;
  125. userid=&quot;anonymous&quot;
  126. password=&quot;me@myorg.com&quot;&gt;
  127. &lt;fileset dir=&quot;htdocs/manual&quot;/&gt;
  128. &lt;/ftp&gt;
  129. </pre>
  130. <p>Logs in to <code>ftp.apache.org</code> as <code>anonymous</code> and
  131. uploads all files in the <code>htdocs/manual</code> directory
  132. to the default directory for that user.</p>
  133. <pre> &lt;ftp server=&quot;ftp.apache.org&quot;
  134. remotedir=&quot;incoming&quot;
  135. userid=&quot;anonymous&quot;
  136. password=&quot;me@myorg.com&quot;
  137. depends=&quot;yes&quot;
  138. &gt;
  139. &lt;fileset dir=&quot;htdocs/manual&quot;/&gt;
  140. &lt;/ftp&gt;</pre>
  141. <p>Logs in to <code>ftp.apache.org</code> as <code>anonymous</code> and
  142. uploads all new or changed files in the <code>htdocs/manual</code> directory
  143. to the <code>incoming</code> directory relative to the default directory
  144. for <code>anonymous</code>.</p>
  145. <pre> &lt;ftp server=&quot;ftp.apache.org&quot;
  146. port=&quot;2121&quot;
  147. remotedir=&quot;/pub/incoming&quot;
  148. userid=&quot;coder&quot;
  149. password=&quot;java1&quot;
  150. depends=&quot;yes&quot;
  151. binary=&quot;no&quot;
  152. &gt;
  153. &lt;fileset dir=&quot;htdocs/manual&quot;&gt;
  154. &lt;include name=&quot;**/*.html&quot;/&gt;
  155. &lt;/fileset&gt;
  156. &lt;/ftp&gt;</pre>
  157. <p>Logs in to <code>ftp.apache.org</code> at port <code>2121</code> as
  158. <code>coder</code> with password <code>java1</code> and uploads all new or
  159. changed HTML files in the <code>htdocs/manual</code> directory to the
  160. <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>
  161. <pre> &lt;ftp server=&quot;ftp.nt.org&quot;
  162. remotedir=&quot;c:\uploads&quot;
  163. userid=&quot;coder&quot;
  164. password=&quot;java1&quot;
  165. separator=&quot;\&quot;
  166. verbose=&quot;yes&quot;</pre>
  167. <PRE>
  168. &gt;
  169. &lt;fileset dir=&quot;htdocs/manual&quot;&gt;
  170. &lt;include name=&quot;**/*.html&quot;/&gt;
  171. &lt;/fileset&gt;
  172. &lt;/ftp&gt;</PRE><p>Logs in to the Windows-based <code>ftp.nt.org</code> as
  173. <code>coder</code> with password <code>java1</code> and uploads all
  174. HTML files in the <code>htdocs/manual</code> directory to the
  175. <code>c:\uploads</code> directory. Progress messages are displayed as each
  176. file is uploaded.</p>
  177. <h3>Getting Files</h3>
  178. <p>Getting files from an FTP server works pretty much the same way as
  179. sending them does. The only difference is that the nested filesets
  180. use the remotedir attribute as the base directory for the files on the
  181. FTP server, and the dir attribute as the local directory to put the files
  182. into. The file structure from the FTP site is preserved on the local machine.</p>
  183. <pre>
  184. &lt;ftp action=&quot;get&quot;
  185. server=&quot;ftp.apache.org&quot;
  186. userid=&quot;anonymous&quot;
  187. password=&quot;me@myorg.com&quot;&gt;
  188. &lt;fileset dir=&quot;htdocs/manual&quot; &gt;
  189. &lt;include name=&quot;**/*.html&quot;/&gt;
  190. &lt;/fileset&gt;
  191. &lt;/ftp&gt;
  192. </pre>
  193. <p>Logs in to <code>ftp.apache.org</code> as <code>anonymous</code> and
  194. recursively downloads all .html files from default directory for that user
  195. into the <code>htdocs/manual</code> directory on the local machine.</p>
  196. <h3>Deleting Files</h3>
  197. As you've probably guessed by now, you use nested fileset elements to
  198. select the files to delete from the remote FTP server. Again, the
  199. filesets are relative to the remote directory, not a local directory. In
  200. fact, the dir attribute of the fileset is ignored completely.
  201. <pre>
  202. &lt;ftp action=&quot;del&quot;
  203. server=&quot;ftp.apache.org&quot;
  204. userid=&quot;anonymous&quot;
  205. password=&quot;me@myorg.com&quot; &gt;
  206. &lt;fileset&gt;
  207. &lt;include name=&quot;**/*.tmp&quot;/&gt;
  208. &lt;/fileset&gt;
  209. &lt;/ftp&gt;
  210. </pre>
  211. <p>Logs in to <code>ftp.apache.org</code> as <code>anonymous</code> and
  212. tries to delete all *.tmp files from the default directory for that user.
  213. If you don't have permission to delete a file, a BuildException is thrown.</p>
  214. <h3>Listing Files</h3>
  215. <pre>
  216. &lt;ftp action=&quot;list&quot;
  217. server=&quot;ftp.apache.org&quot;
  218. userid=&quot;anonymous&quot;
  219. password=&quot;me@myorg.com&quot;
  220. listing=&quot;data/ftp.listing&quot; &gt;
  221. &lt;fileset&gt;
  222. &lt;include name=&quot;**&quot;/&gt;
  223. &lt;/fileset&gt;
  224. &lt;/ftp&gt;
  225. </pre>
  226. <p>This provides a file listing in <code>data/ftp.listing</code> of all the files on
  227. the FTP server relative to the default directory of the <code>anonymous</code>
  228. user. The listing is in whatever format the FTP server normally lists files.</p>
  229. <h3>Creating Directories</h3>
  230. <p>Note that with the mkdir action, the directory to create is specified using the
  231. remotedir attribute.</p>
  232. <pre>
  233. &lt;ftp action=&quot;mkdir&quot;
  234. server=&quot;ftp.apache.org&quot;
  235. userid=&quot;anonymous&quot;
  236. password=&quot;me@myorg.com&quot;
  237. remotedir=&quot;some/remote/dir&quot; /&gt;
  238. </pre>
  239. <p>This creates the directory <code>some/remote/dir</code> beneath the default root
  240. directory. As with all other actions, the directory separator character must be correct
  241. according to the desires of the FTP server.</p>
  242. <hr>
  243. <p align="center">Copyright &copy; 2000,2001 Apache Software Foundation. All rights
  244. Reserved.</p>
  245. </body>
  246. </html>