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.

get.html 11 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <!--
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. -->
  15. <html>
  16. <head>
  17. <meta http-equiv="Content-Language" content="en-us">
  18. <link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
  19. <title>Get Task</title>
  20. </head>
  21. <body>
  22. <h2 id="get">Get</h2>
  23. <h3>Description</h3>
  24. <p>Gets files from URLs. When the verbose option is &quot;on&quot;, this task
  25. displays a '.' for every 100 Kb retrieved. Any URL schema supported by
  26. the runtime is valid here, including http:, ftp: and jar:;
  27. </p>
  28. The <i>usetimestamp</i> option enables you to control downloads so that the remote file is
  29. only fetched if newer than the local copy. If there is no local copy, the download always takes
  30. place. When a file is downloaded, the timestamp of the downloaded file is set to the remote timestamp.
  31. <strong>Note</strong>: This timestamp facility only works on downloads using the HTTP protocol.
  32. <p>
  33. A username and password can be specified, in which case basic 'slightly encoded
  34. plain text' authentication is used. This is only secure over an HTTPS link.
  35. </p>
  36. <p><b>Proxies</b>. <em>Since Apache Ant 1.7.0</em>, Ant running on Java 5 or later can
  37. <a href="../proxy.html">use the proxy settings of the operating
  38. system</a> if enabled with the
  39. <code>-autoproxy</code> option. There is also the
  40. <a href="../Tasks/setproxy.html">&lt;setproxy&gt;</a> task
  41. for earlier Java versions. With proxies turned
  42. on, <code>&lt;get&gt;</code> requests against localhost may not work
  43. as expected, if the request is relayed to the proxy.</p>
  44. <h3>Parameters</h3>
  45. <table>
  46. <tr>
  47. <td valign="top"><b>Attribute</b></td>
  48. <td valign="top"><b>Description</b></td>
  49. <td align="center" valign="top"><b>Required</b></td>
  50. </tr>
  51. <tr>
  52. <td valign="top">src</td>
  53. <td valign="top">the URL from which to retrieve a file.</td>
  54. <td align="center" valign="top">Yes or a nested resource collection</td>
  55. </tr>
  56. <tr>
  57. <td valign="top">dest</td>
  58. <td valign="top">the file or directory where to store the
  59. retrieved file(s).</td>
  60. <td align="center" valign="top">Yes</td>
  61. </tr>
  62. <tr>
  63. <td valign="top">verbose</td>
  64. <td valign="top">show verbose progress information (&quot;on&quot;/&quot;off&quot;).</td>
  65. <td align="center" valign="top">No; default "false"</td>
  66. </tr>
  67. <tr>
  68. <td valign="top">quiet</td>
  69. <td valign="top">Log errors only.(&quot;true&quot;/&quot;false&quot;).</td>
  70. <td align="center" valign="top">No; default "false"</td>
  71. </tr>
  72. <tr>
  73. <td valign="top">ignoreerrors</td>
  74. <td valign="top">Log errors but don't treat as fatal.</td>
  75. <td align="center" valign="top">No; default "false"</td>
  76. </tr>
  77. <tr>
  78. <td valign="top">usetimestamp</td>
  79. <td valign="top">conditionally download a file based on the timestamp of the
  80. local copy. HTTP only</td>
  81. <td align="center" valign="top">No; default "false"</td>
  82. </tr>
  83. <tr>
  84. <td valign="top">username</td>
  85. <td valign="top">username for 'BASIC' http authentication</td>
  86. <td align="center" valign="top">if password is set</td>
  87. </tr>
  88. <tr>
  89. <td valign="top">password</td>
  90. <td valign="top">password: required</td>
  91. <td align="center" valign="top">if username is set</td>
  92. </tr>
  93. <tr>
  94. <td valign="top">maxtime</td>
  95. <td valign="top">Maximum time in seconds a single download may take,
  96. otherwise it will be interrupted and treated like a download
  97. error. <em>Since Ant 1.8.0</em></td>
  98. <td align="center" valign="top">No: default 0 which means no
  99. maximum time</td>
  100. </tr>
  101. <tr>
  102. <td valign="top">retries</td>
  103. <td valign="top">The number of attempts to make for opening the URI.<br/>
  104. The name of the attribute is misleading as a value of 1 means
  105. "don't retry on error" and a value of 0 meant don't even try to
  106. reach the URI at all.<br/>
  107. <em>since Ant 1.8.0</em></td>
  108. <td align="center" valign="top">No; default "3"</td>
  109. </tr>
  110. <tr>
  111. <td valign="top">skipexisting</td>
  112. <td valign="top">skip files that already exist on the local filesystem<br/>
  113. <em>since Ant 1.8.0</em></td>
  114. <td align="center" valign="top">No; default "false"</td>
  115. </tr>
  116. <tr>
  117. <td valign="top">httpusecaches</td>
  118. <td valign="top">HTTP only - if true, allow caching at the
  119. HttpUrlConnection level. if false, turn caching off.<br/>
  120. <strong>Note</strong> this is only a hint to the underlying UrlConnection
  121. class, implementations and proxies are free to ignore the
  122. setting.</td>
  123. <td align="center" valign="top">No; default "true"</td>
  124. </tr>
  125. <tr>
  126. <td valign="top">useragent</td>
  127. <td valign="top">User-Agent HTTP header to send,
  128. defaults to "Apache Ant VERSION"<br/>
  129. <em>since Ant 1.9.3</em></td>
  130. <td align="center" valign="top">No</td>
  131. </tr>
  132. <tr>
  133. <td valign="top">tryGzipEncoding</td>
  134. <td valign="top">When set to true Ant will tell the server it is
  135. willing to accept gzip encoding to reduce the amount of data to
  136. transfer and uncompress the content transparently.<br/>
  137. Setting this to true also means Ant will uncompress
  138. <code>.tar.gz</code> and similar files automatically.<br/>
  139. <em>since Ant 1.9.5</em></td>
  140. <td align="center" valign="top">No; default "false"</td>
  141. </table>
  142. <h3>Parameters specified as nested elements</h3>
  143. <h4>any resource collection</h4>
  144. <p><a href="../Types/resources.html#collection">Resource
  145. Collection</a>s are used to select groups of URLs to download. If
  146. the collection contains more than one resource, the dest attribute
  147. must point to a directory if it exists or a directory will be
  148. created if it doesn't exist. The destination file name use the
  149. last part of the path of the source URL unless you also specify a
  150. mapper.</p>
  151. <h4>mapper</h4>
  152. <p>You can define name transformations by using a
  153. nested <a href="../Types/mapper.html">mapper</a> element. You
  154. can also use any filenamemapper type in place of the mapper
  155. element.</p>
  156. <p>The mapper will receive the resource's name as argument. Any
  157. resource for which the mapper returns no or more than one mapped
  158. name will be skipped. If the returned name is a relative path, it
  159. will be considered relative to the <em>dest</em> attribute.</p>
  160. <h4>header</h4>
  161. <p>Any arbitrary number of HTTP headers can be added to a request.<br/>
  162. The attributes of a nested <code>&lt;header/&gt;</code> node are as follows:</p>
  163. <table>
  164. <tr>
  165. <td valign="top"><b>Attribute</b></td>
  166. <td valign="top"><b>Description</b></td>
  167. <td align="center" valign="top"><b>Required</b></td>
  168. </tr>
  169. <tr>
  170. <td valign="top">name</td>
  171. <td valign="top">The name or key of this header. Cannot be null or empty. Leading and trailing spaces are removed</td>
  172. <td align="center" valign="top">Yes</td>
  173. </tr>
  174. <tr>
  175. <td valign="top">value</td>
  176. <td valign="top">The value to assign to the header. Cannot be null or empty. Leading and trailing spaces are removed</td>
  177. <td align="center" valign="top">Yes</td>
  178. </tr>
  179. </table>
  180. <h3>Examples</h3>
  181. <pre> &lt;get src=&quot;http://ant.apache.org/&quot; dest=&quot;help/index.html&quot;/&gt;</pre>
  182. <p>Gets the index page of http://ant.apache.org/, and stores it in the file <code>help/index.html</code>.</p>
  183. <pre> &lt;get src=&quot;http://www.apache.org/dist/ant/KEYS&quot;
  184. dest=&quot;KEYS&quot;
  185. verbose=&quot;true&quot;
  186. usetimestamp=&quot;true&quot;/&gt;</pre>
  187. <p>
  188. Gets the PGP keys of Ant's (current and past) release managers, if the local copy
  189. is missing or out of date. Uses the verbose option
  190. for progress information.
  191. </p>
  192. <pre> &lt;get src=&quot;https://insecure-bank.org/statement/user=1214&quot;
  193. dest=&quot;statement.html&quot;
  194. username="1214";
  195. password="secret"/&gt;</pre>
  196. <p>
  197. Fetches some file from a server with access control. Because https is being used the
  198. fact that basic auth sends passwords in plaintext is moot if you
  199. ignore the fact that it is part of your build file which may be
  200. readable by third parties. If you need more security, consider using
  201. the <a href="input.html">input task</a> to query for a password.</p>
  202. <p>Using a macro like the following</p>
  203. <pre>
  204. &lt;macrodef name="get-and-checksum">
  205. &lt;attribute name="url"/>
  206. &lt;attribute name="dest"/>
  207. &lt;sequential&gt;
  208. &lt;local name="destdir"/&gt;
  209. &lt;dirname property="destdir" file="@{dest}"/&gt;
  210. &lt;get dest="${destdir}"&gt;
  211. &lt;url url="@{url}"/&gt;
  212. &lt;url url="@{url}.sha1"/&gt;
  213. &lt;firstmatchmapper&gt;
  214. &lt;globmapper from="@{url}.sha1" to="@{dest}.sha"/&gt;
  215. &lt;globmapper from="@{url}" to="@{dest}"/&gt;
  216. &lt;/firstmatchmapper&gt;
  217. &lt;/get&gt;
  218. &lt;local name="checksum.matches"/>
  219. &lt;local name="checksum.matches.fail"/>
  220. &lt;checksum file="@{dest}" algorithm="sha" fileext=".sha"
  221. verifyproperty="checksum.matches"/>
  222. &lt;condition property="checksum.matches.fail">
  223. &lt;equals arg1="${checksum.matches}" arg2="false"/>
  224. &lt;/condition>
  225. &lt;fail if="checksum.matches.fail">Checksum error&lt;/fail>
  226. &lt;/sequential>
  227. &lt;/macrodef>
  228. </pre>
  229. <p>it is possible to download an artifacts together with its SHA1
  230. checksum (assuming a certain naming convention for the checksum
  231. file, of course) and validate the checksum on the fly.</p>
  232. <pre>
  233. &lt;get dest=&quot;downloads&quot;&gt;
  234. &lt;url url=&quot;http://ant.apache.org/index.html&quot;/&gt;
  235. &lt;url url=&quot;http://ant.apache.org/faq.html&quot;/&gt;
  236. &lt;/get&gt;
  237. </pre>
  238. <p>With custom HTTP headers</p>
  239. <pre>
  240. &lt;get src=&quot;http://ant.apache.org/index.html&quot; dest=&quot;downloads&quot;&gt;
  241. &lt;header name=&quot;header1&quot; value=&quot;headerValue1&quot; /&gt;
  242. &lt;header name=&quot;header2&quot; value=&quot;headerValue2&quot; /&gt;
  243. &lt;header name=&quot;header3&quot; value=&quot;headerValue3&quot; /&gt;
  244. &lt;/get&gt;
  245. </pre>
  246. <p>Gets the index and FAQ pages of http://ant.apache.org/, and stores
  247. them in the directory <code>downloads</code> which will be created if
  248. necessary.</p>
  249. </body>
  250. </html>