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

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