function _drush_download_file

8.0.x drush.inc _drush_download_file($url, $destination, $overwrite = TRUE)
6.x drush.inc _drush_download_file($url, $destination, $overwrite = TRUE)
7.x drush.inc _drush_download_file($url, $destination, $overwrite = TRUE)
4.x drush.inc _drush_download_file($url, $destination = FALSE, $overwrite = TRUE)
5.x drush.inc _drush_download_file($url, $destination, $overwrite = TRUE)
master drush.inc _drush_download_file($url, $destination, $overwrite = TRUE)

Download a file using wget, curl or file_get_contents. Does not use download cache.

Parameters

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.

boolean $overwrite: Overwrite any file thats already at the destination.

Return value

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

1 call to _drush_download_file()
drush_download_file in includes/drush.inc
Download a file using wget, curl or file_get_contents, or via download cache.

File

includes/drush.inc, line 836
The drush API implementation and helpers.

Code

function _drush_download_file($url, $destination, $overwrite = TRUE) {
  static $use_wget;
  if ($use_wget === NULL) {
    $use_wget = drush_shell_exec('wget --version');
  }

  $destination_tmp = drush_tempnam('download_file');
  if ($use_wget) {
    drush_shell_exec("wget -q --timeout=30 -O %s %s", $destination_tmp, $url);
  }
  else {
    // Force TLS1+ as per https://github.com/drush-ops/drush/issues/894.
    drush_shell_exec("curl --tlsv1 --fail -s -L --connect-timeout 30 -o %s %s", $destination_tmp, $url);
  }
  if (!drush_file_not_empty($destination_tmp) && $file = @file_get_contents($url)) {
    @file_put_contents($destination_tmp, $file);
  }
  if (!drush_file_not_empty($destination_tmp)) {
    // Download failed.
    return FALSE;
  }

  drush_move_dir($destination_tmp, $destination, $overwrite);
  return $destination;
}