curl_download function

Download file to disk

Download file to disk

Libcurl implementation of C_download (the "internal" download method) with added support for https, ftps, gzip, etc. Default behavior is identical to download.file(), but request can be fully configured by passing a custom handle().

curl_download(url, destfile, quiet = TRUE, mode = "wb", handle = new_handle())

Arguments

  • url: A character string naming the URL of a resource to be downloaded.
  • destfile: A character string with the name where the downloaded file is saved. Tilde-expansion is performed.
  • quiet: If TRUE, suppress status messages (if any), and the progress bar.
  • mode: A character string specifying the mode with which to write the file. Useful values are "w", "wb" (binary), "a" (append) and "ab".
  • handle: a curl handle object

Returns

Path of downloaded file (invisibly).

Details

The main difference between curl_download and curl_fetch_disk

is that curl_download checks the http status code before starting the download, and raises an error when status is non-successful. The behavior of curl_fetch_disk on the other hand is to proceed as normal and write the error page to disk in case of a non success response.

The curl_download function does support resuming and removes the temporary file if the download did not complete successfully. For a more advanced download interface which supports concurrent requests and resuming large files, have a look at the multi_download function.

Examples

# Download large file ## Not run: url <- "http://www2.census.gov/acs2011_5yr/pums/csv_pus.zip" tmp <- tempfile() curl_download(url, tmp) ## End(Not run)

See Also

Advanced download interface: multi_download

  • Maintainer: Jeroen Ooms
  • License: MIT + file LICENSE
  • Last published: 2025-03-24