function _drush_download_file

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

Download a file using wget, curl or file_get_contents. Does not use 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).

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.

Related topics

3 calls to _drush_download_file()
drush_download_file in includes/
Download a file using wget, curl or file_get_contents, or via download cache.
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.
_drush_pm_releasenotes in commands/pm/
Internal function: prints release notes for given drupal projects.


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


function _drush_download_file($url, $destination = FALSE, $overwrite = TRUE) {
  if (!$destination) {
    $destination = getcwd() . '/' . basename($url);

  $destination_tmp = drush_tempnam('download_file');
  drush_shell_exec("wget -q --timeout=30 -O %s %s", $destination_tmp, $url);
  if (!drush_file_not_empty($destination_tmp)) {
    drush_shell_exec("curl -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;