function _drush_sync_via_http_download_file

8.0.x sync_via_http.drush.inc _drush_sync_via_http_download_file($url, $user = FALSE, $password = FALSE, $destination = FALSE, $overwrite = TRUE)
6.x sync_via_http.drush.inc _drush_sync_via_http_download_file($url, $user = FALSE, $password = FALSE, $destination = FALSE, $overwrite = TRUE)
7.x sync_via_http.drush.inc _drush_sync_via_http_download_file($url, $user = FALSE, $password = FALSE, $destination = FALSE, $overwrite = TRUE)
5.x sync_via_http.drush.inc _drush_sync_via_http_download_file($url, $user = FALSE, $password = FALSE, $destination = FALSE, $overwrite = TRUE)
master sync_via_http.drush.inc _drush_sync_via_http_download_file($url, $user = FALSE, $password = FALSE, $destination = FALSE, $overwrite = TRUE)

Downloads a files.

Optionaly uses user authentication, using either wget or curl, as available.

1 call to _drush_sync_via_http_download_file()

File

examples/sync_via_http.drush.inc, line 89
Example "Sync via HTTP" sql-sync command alter.

Code

function _drush_sync_via_http_download_file($url, $user = FALSE, $password = FALSE, $destination = FALSE, $overwrite = TRUE) {
  static $use_wget;
  if ($use_wget === NULL) {
    $use_wget = drush_shell_exec('which wget');
  }

  $destination_tmp = drush_tempnam('download_file');
  if ($use_wget) {
    if ($user && $password) {
      drush_shell_exec("wget -q --timeout=30 --user=%s --password=%s -O %s %s", $user, $password, $destination_tmp, $url);
    }
    else {
      drush_shell_exec("wget -q --timeout=30 -O %s %s", $destination_tmp, $url);
    }
  }
  else {
    if ($user && $password) {
      drush_shell_exec("curl -s -L --connect-timeout 30 --user %s:%s -o %s %s", $user, $password, $destination_tmp, $url);
    }
    else {
      drush_shell_exec("curl -s -L --connect-timeout 30 -o %s %s", $destination_tmp, $url);
    }
  }
  if (!drush_get_context('DRUSH_SIMULATE')) {
    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;
    }
  }
  if ($destination) {
    drush_move_dir($destination_tmp, $destination, $overwrite);
    return $destination;
  }
  return $destination_tmp;
}