download makes a get request of the provided url
 and writes the body to the provided filename.

 download 'url', 'save_file'
488049
def download(url, filename)
      File.open(filename, "w") do |file|
        file.puts(make_request(:get, url, headers: {'content-type' => 'application/atom+xml'}).body)
      end
    end
354178
public function download($fileName, $url = null, $requestBody = null, $method = 'GET')
    {
        $result = $this->saveFile($fileName)->send($url, $requestBody, $method);
        $this->saveFileOption = array();
        return $result;
    }
426998
def download_archive(sources):
    

    # last element is expected to be the local archive name
    save_to = sources[-1]

    # not downloading the file again if it exists
    if os.path.exists(save_to):
        print('not downloading {0} since it exists locally'.format(save_to))
        return

    # try all possible sources one by one
    for url in sources[:-1]:
        # make five attempts per source
        for i in range(5):
            # first attempt to get a response
            response = urlopen(url)

            # handling redirections
            u = urlopen(response.geturl())

            meta = u.info()
            if meta.get('Content-Length') and len(meta.get('Content-Length')) > 0:
                filesz = int(meta.get('Content-Length'))
                if os.path.exists(save_to) and os.path.getsize(save_to) == filesz:
                    print('not downloading {0} since it exists locally'.format(save_to))
                    return

                print('downloading: {0} ({1} bytes)...'.format(save_to, filesz), end=' ')
                with open(save_to, 'wb') as fp:
                    block_sz = 8192
                    while True:
                        buff = u.read(block_sz)
                        if not buff:
                            break
                        fp.write(buff)

                print('done')
                break
        else:
            continue

        break  # successfully got the file
    else:
        assert 0, 'something went wrong -- cannot download {0}'.format(save_to)
1081604
def download(url, filename=None):
	
	# requirements os, shutil, urllib.parse, urllib.request
	if not filename:
		url_parts = urllib.parse.urlparse(url)
		filename = os.path.basename(url_parts.path)
	url_h = urllib.request.urlopen(url)
	with open(filename, 'wb') as file_h:
		shutil.copyfileobj(url_h, file_h)
	url_h.close()
	return
1234298
def save(url, destination):
    
    r = requests.get(url, stream=True)

    with open(destination, 'wb') as fd:
        for chunk in r.iter_content(chunk_size=128):
            fd.write(chunk)
1246003
def download_url_to_path(self, url, path, force=False):
        

        path_exists = isfile(path)
        if not path_exists or force:

            dir = dirname(path)
            if not exists(dir):
                if self.verbose:
                    print("CREATE %s" % dir)
                makedirs(dir)

            try:
                u = urlopen(url)
            except HTTPError as e:
                u = None
                print("HTTP error code %r.  Please check you ~/.netrc has the correct authorization" % e.code)

            if u:
                with open(path, 'wb') as file:
                    meta = u.info()
                    meta_func = meta.getheaders \
                        if hasattr(meta, 'getheaders') else meta.get_all
                    meta_length = meta_func("Content-Length")
                    file_size = None
                    if meta_length:
                        file_size = int(meta_length[0])
                    if self.verbose:
                        print("Downloading: {0} Bytes: {1}".format(url, file_size))

                    file_size_dl = 0
                    block_sz = 8192
                    while True:
                        buffer = u.read(block_sz)
                        if not buffer:
                            break
                        file_size_dl += len(buffer)
                        file.write(buffer)

                if self.verbose:
                    if path_exists:
                        print("OVERWRITING %s" % path)
                    else:
                        print("CREATE %s" % path)

        elif self.verbose:
            print("FOUND %s (already downloaded)" % path)
411300
function download(url) {
        var a = document.createElement('a');
        a.href = url;
        a.setAttribute('download', 'doc');
        document.body.appendChild(a);
        a.click();
        document.body.removeChild(a);
    }
5268
def download_url(url, dir_name='.', save_name=None, store_directory=None, messages=True, suffix=''):
    """"""
    if sys.version_info>=(3,0):
        from urllib.parse import quote
        from urllib.request import urlopen 
        from urllib.error import HTTPError, URLError
    else:
        from urllib2 import quote
        from urllib2 import urlopen
        from urllib2 import URLError as HTTPError
    i = url.rfind('/')
    file = url[i+1:]
    if store_directory is not None:
        dir_name = os.path.join(dir_name, store_directory)
    if save_name is None:
        save_name = file
    save_name = os.path.join(dir_name, save_name)
    print("Downloading ", url, "->", save_name)
    if not os.path.exists(dir_name):
        os.makedirs(dir_name)
    try:
        response = urlopen(url+suffix)
    except HTTPError as e:
        if not hasattr(e, "code"):
            raise
        if e.code > 399 and e.code<500:
            raise ValueError('Tried url ' + url + suffix + ' and received client error ' + str(e.code))
        elif e.code > 499:
            raise ValueError('Tried url ' + url + suffix + ' and received server error ' + str(e.code))
    except URLError as e:
        raise ValueError('Tried url ' + url + suffix + ' and failed with error ' + str(e.reason))
    with open(save_name, 'wb') as f:
        meta = response.info()
        content_length_str = meta.get("Content-Length")
        if content_length_str:
            #if sys.version_info>=(3,0):
            try:
                file_size = int(content_length_str)
            except:
                try: 
                    file_size = int(content_length_str[0])
                except:
                    file_size = None
            if file_size == 1:
                file_size = None
            #else:
            #    file_size = int(content_length_str)
        else:
            file_size = None
        
        status = ""
        file_size_dl = 0
        block_sz = 8192
        line_length = 30
        percentage = 1./line_length
        
        if file_size:
            print("|"+"{:^{ll}}".format("Downloading {:7.3f}MB".format(file_size/(1048576.)), ll=line_length)+"|")
            from itertools import cycle
            cycle_str = cycle('>')
            sys.stdout.write("|")
                    
        while True:
            buff = response.read(block_sz)
            if not buff:
                break
            file_size_dl += len(buff)
            f.write(buff)
            
            # If content_length_str was incorrect, we can end up with many too many equals signs, catches this edge case
            #correct_meta = float(file_size_dl)/file_size <= 1.0
            
            if file_size:
                if (float(file_size_dl)/file_size) >= percentage:
                    sys.stdout.write(next(cycle_str))
                    sys.stdout.flush()
                    percentage += 1./line_length
                #percentage = "="*int(line_length*float(file_size_dl)/file_size)
                #status = r"[{perc: <{ll}}] {dl:7.3f}/{full:.3f}MB".format(dl=file_size_dl/(1048576.), full=file_size/(1048576.), ll=line_length, perc=percentage)
            else:
                sys.stdout.write(" "*(len(status)) + "\r")
                status = r"{dl:7.3f}MB".format(dl=file_size_dl/(1048576.),
                                                                       ll=line_length,
                                                                       perc="."*int(line_length*float(file_size_dl/(10*1048576.))))
                sys.stdout.write(status)
                sys.stdout.flush()

            #sys.stdout.write(status)
        
        if file_size:
            sys.stdout.write("|")
            sys.stdout.flush()

        print(status)
709703
function download(downloadUrl, filename, callback, ondata) {
    var url = require("url").parse(downloadUrl);
    var out = require("fs").createWriteStream(filename, { flags: 'w', encoding: null, mode: 0666 });
    var bytes = 0, total = -1;
    var options = {
        "hostname" : url["host"],
        "method" : "GET",
        "path" : url["path"],
        "agent" : false
    }

    // Reconfigure request options if an HTTP proxy setting exists
    if (process.env.http_proxy) {
        var http_proxy = require("url").parse(process.env.http_proxy);
        options["hostname"] = http_proxy["hostname"];
        options["port"] = http_proxy["port"];
        options["path"] = url["href"];
        options["headers"] = {
            "Host" : url["host"]
        };
    }

    var req = require(path.join(__dirname, "..", "lib", "follow-redirects.js")).http.request(options,
                                                                                             function(res) {
        if (res.headers["content-length"]) {
            total = parseInt(res.headers["content-length"], 10);
        }
        if (res.statusCode != 200) {
            res.setEncoding(null);
            callback(new Error("Download failed: HTTP status code "+res.statusCode), -1);
            return;
        }
        res.on("data", function(chunk) {
            bytes += chunk.length;
            if (ondata) ondata(chunk.length, total);
            out.write(chunk);
        });

        res.on("end", function() {
            callback(null, bytes);
        });
    });
    req.on("error", function(e) {
        callback(e, -1);
    });
    req.end();
}
171947
def downloadFile(url,outfile=None): 
    '''  '''
    if not outfile:
        outfile = url.split('/')[-1]
    r = requests.get(url, stream=True)
    with open(outfile, 'wb') as f:
        for chunk in r.iter_content(chunk_size=1024): 
            if chunk: 
                f.write(chunk)
    return outfile
823354
def save_url(path, url)
      resp = request('/files/save_url', path: path, url: url)
      parse_tagged_response(resp)
    end
768398
def download_file(url, local_filename):
    
    local_filename = os.path.abspath(local_filename)
    path = os.path.dirname(local_filename)
    if not os.path.isdir(path):
        os.makedirs(path)

    with tqdm(unit='B', unit_scale=True) as progress:
        def report(chunk, chunksize, total):
            progress.total = total
            progress.update(chunksize)
        return urlretrieve(url, local_filename, reporthook=report)
514869
def download(self, output_dir, url, overwrite):
        
        tmp = self.url2tmp(output_dir, url)
        if os.path.isfile(tmp) and not overwrite:
            logging.info("File {0} already exists. Skipping download.".format(tmp))
            return tmp
        f = open(tmp, 'wb')
        logging.info("Downloading {0}".format(url))
        res = requests.get(url, stream=True)
        if res.status_code != 200:
            # failed to download, cleanup and raise exception
            f.close()
            os.remove(tmp)
            error = "{0}\n\nFailed to download < {0} >".format(res.content, url)
            raise IOError(error)
        for block in res.iter_content(1024):
            f.write(block)
        f.close()
        return tmp
607648
def _download_file(self, url, apikey=None):
        
        import gzip
        import tempfile

        cty = {}
        cty_date = ""
        cty_file_path = None

        filename = None

        # download file
        if apikey: # clublog
            response = requests.get(url+"?api="+apikey, timeout=10)
        else: # country-files.com
            response = requests.get(url, timeout=10)

        if not self._check_html_response(response):
            raise LookupError

        #Clublog Webserver Header
        if "Content-Disposition" in response.headers:
            f = re.search('filename=".+"', response.headers["Content-Disposition"])
            if f:
                f = f.group(0)
                filename = re.search('".+"', f).group(0).replace('"', '')

        #Country-files.org webserver header
        else:
            f = re.search('/.{4}plist$', url)
            if f:
                f = f.group(0)
                filename = f[1:]

        if not filename:
            filename = "cty_" + self._generate_random_word(5)

        download_file_path = os.path.join(tempfile.gettempdir(), filename)
        with open(download_file_path, "wb") as download_file:
            download_file.write(response.content)
        self._logger.debug(str(download_file_path) + " successfully downloaded")

        # unzip file, if gz
        if os.path.splitext(download_file_path)[1][1:] == "gz":

            download_file = gzip.open(download_file_path, "r")
            try:
                cty_file_path = os.path.join(os.path.splitext(download_file_path)[0])
                with open(cty_file_path, "wb") as cty_file:
                    cty_file.write(download_file.read())
                self._logger.debug(str(cty_file_path) + " successfully extracted")
            finally:
                download_file.close()
        else:
            cty_file_path = download_file_path

        return cty_file_path
655150
def download_file(path, local_drive_path)
      uri = URI.parse(Addressable::URI.escape(@url + path))
      http_request = build_http_object(uri)
      req = build_request(:get, uri, {}, @api_version.to_s)

      http_request.start do |http|
        http.request(req) do |res|
          response_handler(res) unless res.code.to_i.between?(200, 204)
          File.open(local_drive_path, 'wb') do |file|
            res.read_body do |segment|
              file.write(segment)
            end
          end
        end
      end
      true
    end
843883
def download(cls, url, filename=None):
        
        return utility.download(url, cls.directory(), filename)
879866
def download_file(cls, url, local_file_name=None, force=False, chunk_size=1024):
        

        local_file_name = local_file_name if local_file_name else url.split('/')[-1]
        filepath = os.path.join(cls.data_path, local_file_name)

        if not os.path.exists(filepath) or force:
            try:
                headers = requests.head(url, allow_redirects=True).headers
                length = headers.get('Content-Length')

                logger.info("Starting download of {} file with {} bytes ...".format(url, length))

                widgets = [
                    'Downloading file please wait...', progressbar.Percentage(),
                    ' ', progressbar.Bar(),
                    ' ', progressbar.ETA(),
                    ' ', progressbar.FileTransferSpeed(),
                ]
                bar = progressbar.ProgressBar(widgets=widgets, max_value=int(length) + chunk_size).start()

                r = requests.get(url, stream=True)

                with open(filepath, 'wb') as f:
                    total_chunk = 0

                    for chunk in r.iter_content(chunk_size):
                        if chunk:
                            f.write(chunk)
                            total_chunk += chunk_size
                            bar.update(total_chunk)

                bar.finish()

            except:
                if os.path.exists(filepath):
                    os.remove(filepath)

                raise

        return filepath