Get Task

## Get

### Description

Gets files from URLs. When the verbose option is "on", this task displays a '.' for every 100 Kb retrieved. Any URL schema supported by the runtime is valid here, including http:, ftp: and jar:;

The usetimestamp option enables you to control downloads so that the remote file is only fetched if newer than the local copy. If there is no local copy, the download always takes place. When a file is downloaded, the timestamp of the downloaded file is set to the remote timestamp. NB: This timestamp facility only works on downloads using the HTTP protocol.

A username and password can be specified, in which case basic 'slightly encoded plain text' authentication is used. This is only secure over an HTTPS link.

Proxies. Since Apache Ant 1.7.0, Ant running on Java1.5 or later can use the proxy settings of the operating system if enabled with the `-autoproxy` option. There is also the <setproxy> task for earlier Java versions. With proxies turned on, `<get>` requests against localhost may not work as expected, if the request is relayed to the proxy.

### Parameters

Attribute | Description | Required
src | the URL from which to retrieve a file. | Yes or a nested resource collection
dest | the file or directory where to store the retrieved file(s). | Yes
verbose | show verbose progress information ("on"/"off"). | No; default "false"
ignoreerrors | Log errors but don't treat as fatal. | No; default "false"
usetimestamp | conditionally download a file based on the timestamp of the local copy. HTTP only | No; default "false"
username | username for 'BASIC' http authentication | if password is set
password | password: required | if username is set
maxtime | Maximum time in seconds a single download may take, otherwise it will be interrupted and treated like a download error. Since Ant 1.8.0 | No: default 0 which means no maximum time
retries | the per download number of retries on error since Ant 1.8.0 | No; default "3"
skipexisting | skip files that already exist on the local filesystem since Ant 1.8.0 | No; default "false"
httpusecaches | HTTP only - if true, allow caching at the HttpUrlConnection level. if false, turn caching off. Note this is only a hint to the underlying UrlConnection class, implementations and proxies are free to ignore the setting. | No; default "true"

### Parameters specified as nested elements

#### any resource collection

Resource Collections are used to select groups of URLs to download. If the collection contains more than one resource, the dest attribute must point to a directory if it exists or a directory will be created if it doesn't exist. The destination file name use the last part of the path of the source URL unless you also specify a mapper.

#### mapper

You can define name transformations by using a nested mapper element. You can also use any filenamemapper type in place of the mapper element.

The mapper will receive the resource's name as argument. Any resource for which the mapper returns no or more than one mapped name will be skipped. If the returned name is a relative path, it will be considered relative to the dest attribute.

### Examples

      <get src="http://ant.apache.org/" dest="help/index.html"/>

Gets the index page of http://ant.apache.org/, and stores it in the file `help/index.html`.

      <get src="http://www.apache.org/dist/ant/KEYS"
        dest="KEYS"
        verbose="true"
        usetimestamp="true"/>

Gets the PGP keys of Ant's (current and past) release managers, if the local copy is missing or out of date. Uses the verbose option for progress information.

      <get src="https://insecure-bank.org/statement/user=1214"
        dest="statement.html"
        username="1214";
        password="secret"/>

Fetches some file from a server with access control. Because https is being used the fact that basic auth sends passwords in plaintext is moot if you ignore the fact that it is part of your build file which may be readable by third parties. If you need more security, consider using the input task to query for a password.

Using a macro like the following

      <macrodef name="get-and-checksum">
        <attribute name="url"/>
        <attribute name="dest"/>
        <sequential>
          <local name="destdir"/>
          <dirname property="destdir" file="@{dest}"/>
          <get dest="${destdir}">
            <url url="@{url}"/>
            <url url="@{url}.sha1"/>
            <firstmatchmapper>
              <globmapper from="@{url}.sha1" to="@{dest}.sha"/>
              <globmapper from="@{url}" to="@{dest}"/>
            </firstmatchmapper>
          </get>
          <local name="checksum.matches"/>
          <local name="checksum.matches.fail"/>
          <checksum file="@{dest}" algorithm="sha" fileext=".sha"
                    verifyproperty="checksum.matches"/>
          <condition property="checksum.matches.fail">
            <equals arg1="${checksum.matches}" arg2="false"/>
          </condition>
          <fail if="checksum.matches.fail">Checksum error</fail>
        </sequential>
      </macrodef>

it is possible to download an artifacts together with its SHA1 checksum (assuming a certain naming convention for the checksum file, of course) and validate the checksum on the fly.

    <get dest="downloads">
      <url url="http://ant.apache.org/index.html"/>
      <url url="http://ant.apache.org/faq.html"/>
    </get>

Gets the index and FAQ pages of http://ant.apache.org/, and stores them in the directory `downloads` which will be created if necessary.