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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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><a name="get">Get</a></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. NB: 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>. Since Ant 1.7.0, Ant running on Java1.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="../OptionalTasks/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 border="1" cellpadding="2" cellspacing="0">
  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">ignoreerrors</td>
  69. <td valign="top">Log errors but don't treat as fatal.</td>
  70. <td align="center" valign="top">No; default "false"</td>
  71. </tr>
  72. <tr>
  73. <td valign="top">usetimestamp</td>
  74. <td valign="top">conditionally download a file based on the timestamp of the
  75. local copy. HTTP only</td>
  76. <td align="center" valign="top">No; default "false"</td>
  77. </tr>
  78. <tr>
  79. <td valign="top">username</td>
  80. <td valign="top">username for 'BASIC' http authentication</td>
  81. <td align="center" valign="top">if password is set</td>
  82. </tr>
  83. <tr>
  84. <td valign="top">password</td>
  85. <td valign="top">password: required </td>
  86. <td align="center" valign="top">if username is set</td>
  87. </tr>
  88. <tr>
  89. <td valign="top">maxtime</td>
  90. <td valign="top">Maximum time in seconds a single download may take,
  91. otherwise it will be interrupted and treated like a download
  92. error. <em>Since Ant 1.8.0</em></td>
  93. <td align="center" valign="top">No: default 0 which means no
  94. maximum time</td>
  95. </tr>
  96. <tr>
  97. <td valign="top">retries</td>
  98. <td valign="top">the per download number of retries on error<br/>
  99. <em>since Ant 1.8.0</em></td>
  100. <td align="center" valign="top">No; default "3"</td>
  101. </tr>
  102. <tr>
  103. <td valign="top">skipexisting</td>
  104. <td valign="top">skip files that already exist on the local filesystem<br/>
  105. <em>since Ant 1.8.0</em></td>
  106. <td align="center" valign="top">No; default "false"</td>
  107. </tr>
  108. <tr>
  109. <td valign="top">httpusecaches</td>
  110. <td valign="top">HTTP only - if true, allow caching at the
  111. HttpUrlConnection level. if false, turn caching off.<br/>
  112. <b>Note</b> this is only a hint to the underlying UrlConnection
  113. class, implementations and proxies are free to ignore the
  114. setting.</td>
  115. <td align="center" valign="top">No; default "true"</td>
  116. </tr>
  117. </table>
  118. <h3>Parameters specified as nested elements</h3>
  119. <h4>any resource collection</h4>
  120. <p><a href="../CoreTypes/resources.html#collection">Resource
  121. Collection</a>s are used to select groups of URLs to download. If
  122. the collection contains more than one resource, the dest attribute
  123. must point to a directory if it exists or a directory will be
  124. created if it doesn't exist. The destination file name use the
  125. last part of the path of the source URL unless you also specify a
  126. mapper.</p>
  127. <h4>mapper</h4>
  128. <p>You can define name transformations by using a
  129. nested <a href="../CoreTypes/mapper.html">mapper</a> element. You
  130. can also use any filenamemapper type in place of the mapper
  131. element.</p>
  132. <p>The mapper will receive the resource's name as argument. Any
  133. resource for which the mapper returns no or more than one mapped
  134. name will be skipped. If the returned name is a relative path, it
  135. will be considered relative to the <em>dest</em> attribute.</p>
  136. <h3>Examples</h3>
  137. <pre> &lt;get src=&quot;http://ant.apache.org/&quot; dest=&quot;help/index.html&quot;/&gt;</pre>
  138. <p>Gets the index page of http://ant.apache.org/, and stores it in the file <code>help/index.html</code>.</p>
  139. <pre> &lt;get src=&quot;http://www.apache.org/dist/ant/KEYS&quot;
  140. dest=&quot;KEYS&quot;
  141. verbose=&quot;true&quot;
  142. usetimestamp=&quot;true&quot;/&gt;</pre>
  143. <p>
  144. Gets the PGP keys of Ant's (current and past) release managers, if the local copy
  145. is missing or out of date. Uses the verbose option
  146. for progress information.
  147. </p>
  148. <pre> &lt;get src=&quot;https://insecure-bank.org/statement/user=1214&quot;
  149. dest=&quot;statement.html&quot;
  150. username="1214";
  151. password="secret"/&gt;</pre>
  152. <p>
  153. Fetches some file from a server with access control. Because https is being used the
  154. fact that basic auth sends passwords in plaintext is moot if you
  155. ignore the fact that it is part of your build file which may be
  156. readable by third parties. If you need more security, consider using
  157. the <a href="input.html">input task</a> to query for a password.</p>
  158. <p>Using a macro like the following</p>
  159. <pre>
  160. &lt;macrodef name="get-and-checksum">
  161. &lt;attribute name="url"/>
  162. &lt;attribute name="dest"/>
  163. &lt;sequential&gt;
  164. &lt;local name="destdir"/&gt;
  165. &lt;dirname property="destdir" file="@{dest}"/&gt;
  166. &lt;get dest="${destdir}"&gt;
  167. &lt;url url="@{url}"/&gt;
  168. &lt;url url="@{url}.sha1"/&gt;
  169. &lt;firstmatchmapper&gt;
  170. &lt;globmapper from="@{url}.sha1" to="@{dest}.sha"/&gt;
  171. &lt;globmapper from="@{url}" to="@{dest}"/&gt;
  172. &lt;/firstmatchmapper&gt;
  173. &lt;/get&gt;
  174. &lt;local name="checksum.matches"/>
  175. &lt;local name="checksum.matches.fail"/>
  176. &lt;checksum file="@{dest}" algorithm="sha" fileext=".sha"
  177. verifyproperty="checksum.matches"/>
  178. &lt;condition property="checksum.matches.fail">
  179. &lt;equals arg1="${checksum.matches}" arg2="false"/>
  180. &lt;/condition>
  181. &lt;fail if="checksum.matches.fail">Checksum error&lt;/fail>
  182. &lt;/sequential>
  183. &lt;/macrodef>
  184. </pre>
  185. <p>it is possible to download an artifacts together with its SHA1
  186. checksum (assuming a certain naming convention for the checksum
  187. file, of course) and validate the checksum on the fly.</p>
  188. <pre>
  189. &lt;get dest=&quot;downloads&quot;&gt;
  190. &lt;url url=&quot;http://ant.apache.org/index.html&quot;/&gt;
  191. &lt;url url=&quot;http://ant.apache.org/faq.html&quot;/&gt;
  192. &lt;/get&gt;
  193. </pre>
  194. <p>Gets the index and FAQ pages of http://ant.apache.org/, and stores
  195. them in the directory <code>downloads</code> which will be created if
  196. necessary.</p>
  197. </body>
  198. </html>