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

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