function drush_download_file

8.0.x drush_download_file($url, $destination = FALSE, $cache_duration = 0)
6.x drush_download_file($url, $destination = FALSE, $cache_duration = 0)
7.x drush_download_file($url, $destination = FALSE, $cache_duration = 0)
4.x drush_download_file($url, $destination = FALSE, $cache_duration = 0)
5.x drush_download_file($url, $destination = FALSE, $cache_duration = 0)
master drush_download_file($url, $destination = FALSE, $cache_duration = 0)

Download a file using wget, curl or file_get_contents, or via download cache.


string $url: The url of the file to download.

string $destination: The name of the file to be saved, which may include the full path. Optional, if omitted the filename will be extracted from the url and the file downloaded to the current working directory (Drupal root if bootstrapped).

integer $cache_duration: The acceptable age of a cached file. If cached file is too old, a fetch will occur and cache will be updated. Optional, if ommitted the file will be fetched directly.

Return value

string The path to the downloaded file, or FALSE if the file could not be downloaded.

7 calls to drush_download_file()
drush_hook_pre_pm_enable in docs/drush.api.php
Automatically download project dependencies at pm-enable time. Use a pre-pm_enable hook to download before your module is enabled, or a post-pm_enable hook (drush_hook_post_pm_enable) to run after your module is enabled.
drush_lib_fetch in includes/
Download and extract a tarball to the lib directory.
drush_xkcd_display in examples/
Retrieve and display a table of metadata for an XKCD cartoon, then retrieve and display the cartoon using a specified image viewer.
package_handler_download_project in commands/pm/package_handler/
Download a project.
release_info_print_releasenotes in commands/pm/release_info/
Prints release notes for given projects.

... See full list


includes/, line 723
The drush API implementation and helpers.


function drush_download_file($url, $destination = FALSE, $cache_duration = 0) {
  // Generate destination if omitted.
  if (!$destination) {
    $file = basename(current(explode('?', $url, 2)));
    $destination = getcwd() . '/' . basename($file);

  // Simply copy local files to the destination
  if (!_drush_is_url($url)) {
    return copy($url, $destination) ? $destination : FALSE;

  if (drush_get_option('cache') && $cache_duration !== 0 && $cache_file = drush_download_file_name($url)) {
    // Check for cached, unexpired file.
    if (file_exists($cache_file) && filectime($cache_file) > ($_SERVER['REQUEST_TIME'] -$cache_duration)) {
      drush_log(dt('!name retrieved from cache.', array('!name' => $cache_file)));
    else {
      if (_drush_download_file($url, $cache_file, TRUE)) {
        // Cache was set just by downloading file to right location.
      elseif (file_exists($cache_file)) {
        drush_log(dt('!name retrieved from an expired cache since refresh failed.', array('!name' => $cache_file)), 'warning');
      else {
        $cache_file = FALSE;

    if ($cache_file && copy($cache_file, $destination)) {
      // Copy cached file to the destination
      return $destination;
  elseif ($return = _drush_download_file($url, $destination)) {
    return $return;

  // Unable to retrieve from cache nor download.
  return FALSE;