Download the ZIP file with the plugin package from the given location

@param string $url URL to the file
@param string $tofile full path to where to store the downloaded file
@return bool false on error
330370
protected function download_plugin_zip_file($url, $tofile) {

        if (file_exists($tofile)) {
            $this->debug('Error fetching plugin ZIP: target location exists.');
            return false;
        }

        $status = $this->download_file_content($url, $tofile);

        if (!$status) {
            $this->debug('Error fetching plugin ZIP.');
            @unlink($tofile);
            return false;
        }

        return true;
    }
1326658
public function download($url)
    {
        if (!$this->curl) {
            $this->curl = curl_init();
            curl_setopt($this->curl, CURLOPT_HTTPHEADER, array(
                'User-Agent: gender-api-client/1.0',
                'Content-Type: application/json'
            ));
            curl_setopt($this->curl, CURLOPT_TIMEOUT, 5);
            curl_setopt($this->curl, CURLOPT_CONNECTTIMEOUT, 5);
            curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);

            if ($this->proxyHost) {
                curl_setopt($this->curl, CURLOPT_PROXY, $this->proxyHost);
                curl_setopt($this->curl, CURLOPT_PROXYPORT, $this->proxyPort);
            }
        }

        curl_setopt($this->curl, CURLOPT_URL, $url);

        $response = @curl_exec($this->curl);
        $responseCode = curl_getinfo($this->curl, CURLINFO_RESPONSE_CODE);

        if ($response === false || $responseCode != 200) {
            $lastError = curl_error($this->curl);
            throw new NetworkErrorException($lastError);
        }

        return $response;
    }
1012090
private function getFile($url)
	{
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_HEADER, false);
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
		$result = curl_exec($ch);
		curl_close($ch);

		$response = json_decode($result, TRUE);
		if (is_array($response) && count($response) > 0 && (!isset($response['status']) || $response['status'] != '404')) {
			return $response;
		}
		
		return false;
	}
372060
public function download($url, $pathToStore)
    {
        if (!URL::checkUrl($url)) {
            /**
             * The URL is not valid
             */
            throw new HttpUrlException(
                $this->translator->trans(
                    "Tried to download a file, but the URL was not valid: %url",
                    [
                        "%url" => $url
                    ]
                )
            );
        }

        /**
         * Try to get the file if it is online
         */
        $con = curl_init($url);
        curl_setopt($con, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($con, CURLOPT_FOLLOWLOCATION, true);

        $response = curl_exec($con);
        $errno = curl_errno($con);
        $curlErrorMessage = curl_error($con);

        $httpCode = curl_getinfo($con, CURLINFO_HTTP_CODE);

        curl_close($con);

        if (false === $response || $errno !== 0 ||
            ($httpCode != "200" && $httpCode != "204")
            ) {
            /**
             * The server is down ? The file doesn't exist ? Anything else ?
             */
            $errorMessage = $this->translator->trans(
                "cURL errno %errno, http code %http_code on link \"%path\": %error",
                [
                    "%errno" => $errno,
                    "%path" => $url,
                    "%error" => $curlErrorMessage,
                    "%http_code" => $httpCode,
                ]
            );

            $this->logger
                ->error($errorMessage)
            ;

            throw new FileNotFoundException($errorMessage);
        }

        /**
         * Inform that you've downloaded a file
         */
        $this->logger
            ->info(
                $this->translator->trans(
                    "The file %path has been successfully downloaded",
                    [
                        "%path" => $url
                    ]
                )
            )
        ;

        /**
         * Then try to write it on the disk
         */
        $file = @fopen($pathToStore, "w");

        if ($file === false) {
            $translatedErrorMessage = $this->translator->trans(
                "Failed to open a writing stream on the file: %file",
                [
                    "%file" => $pathToStore
                ]
            );

            $this->logger->error($translatedErrorMessage);
            throw new \ErrorException($translatedErrorMessage);
        }

        fputs($file, $response);
        fclose($file);
    }
361694
protected function verifyImportFromUrl($url)
    {
        $extension = strtolower(pathinfo($url, PATHINFO_EXTENSION));

        if (static::FILE_EXTENSION != $extension) {
            throw new BadRequestException("Only package files ending with '" .
                static::FILE_EXTENSION .
                "' are allowed for import.");
        }

        try {
            // need to download and extract zip file and move contents to storage
            $file = FileUtilities::importUrlFileToTemp($url);
        } catch (\Exception $ex) {
            throw new InternalServerErrorException("Failed to import package from $url. {$ex->getMessage()}");
        }

        $this->setZipFile($file);
    }
248037
private function downloadFile($url)
    {
        $tmpFile = tempnam(sys_get_temp_dir(), 'utft');
        $extension = pathinfo($url, PATHINFO_EXTENSION);

        if (!empty($extension)) {
            $tmpFile = sprintf("%s.%s", $tmpFile, $extension);
        }

        $fp = fopen($tmpFile, 'w+');
        if (false === $fp) {
            throw new \RuntimeException(sprintf('Cannot open temporary file `%s`', $tmpFile));
        }

        $ch = curl_init();

        curl_setopt_array($ch, [
            CURLOPT_URL => $url,
            CURLOPT_BINARYTRANSFER => 1,
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_FILE => $fp,
            CURLOPT_TIMEOUT => 50,
        ]);

        if (false === curl_exec($ch)) {
            throw new \RuntimeException(sprintf('Cannot download remote file. Curl error: `%s`', curl_error($ch)));
        }
        curl_close($ch);

        return $tmpFile;
    }
919656
public function download($url, $progress, $to = null)
    {
        list($bucket, $key) = $this->determineBucketAndKey($url);

        if ($progress) {
            $this->io->write("    Downloading: <comment>connection...</comment>", false);
        }

        try {
            $params = array(
                'Bucket'                => $bucket,
                'Key'                   => $key
            );

            if ($to) {
                $params['SaveAs'] = $to;
            }
    
            $s3     = $this->s3factory($this->config);
            $result = $s3->getObject($params);

            if ($progress) {
                $this->io->overwrite("    Downloading: <comment>100%</comment>");
            }

            if ($to) {
                if (false === file_exists($to) || !filesize($to)) {
                    $errorMessage = sprintf(
                        "Unknown error occurred: '%s' was not downloaded from '%s'.",
                        $key,
                        $url
                    );
                    throw new TransportException($errorMessage);
                }
            } else {
                return $result['Body'];
            }
        } catch (CredentialsException $e) {
            $msg = "Please add key/secret or a profile name into config.json or set up an IAM profile for your EC2 instance.";
            throw new TransportException($msg, 403, $e);
        } catch(S3Exception $e) {
            throw new TransportException("Connection to Amazon S3 failed.", null, $e);
        } catch (TransportException $e) {
            throw $e; // just re-throw
        } catch (\Exception $e) {
            throw new TransportException("Problem?", null, $e);
        }

        return $this;
    }
145569
public function downloadFileFromURL($url)
    {
        $request     = new \Google_Http_Request($url, 'GET', null, null);
        $httpRequest = $this->service->getClient()
           ->getAuth()
           ->authenticatedRequest($request);
        if ($httpRequest->getResponseHttpCode() == 200) {
            return $httpRequest->getResponseBody();
        } else {
            // An error occurred.
            return null;
        }
    }
743768
protected void downloadArtifactTo(URL artifactUrl, File pluginFile, IAsyncResultHandler<File> handler) {
        InputStream istream = null;
        OutputStream ostream = null;
        try {
            URLConnection connection = artifactUrl.openConnection();
            connection.connect();
            if (connection instanceof HttpURLConnection) {
                HttpURLConnection httpConnection = (HttpURLConnection) connection;
                if (httpConnection.getResponseCode() != 200) {
                    handler.handle(AsyncResultImpl.create(null));
                    return;
                }
            }
            istream = connection.getInputStream();
            ostream = new FileOutputStream(pluginFile);
            IOUtils.copy(istream, ostream);
            ostream.flush();
            handler.handle(AsyncResultImpl.create(pluginFile));
        } catch (Exception e) {
            handler.handle(AsyncResultImpl.<File>create(e));
        } finally {
            IOUtils.closeQuietly(istream);
            IOUtils.closeQuietly(ostream);
        }
    }
461414
private function getFileContent($pathToFile)
    {
        $level = error_reporting(0);
        $content = file_get_contents($pathToFile);
        error_reporting($level);

        if (false === $content) {
            $error = error_get_last();
            throw new RuntimeException($error['message']);
        }

        return $content;
    }
1231324
public static function downloadFile(string $url) : string
    {
        $downloadedFilepath = tempnam(sys_get_temp_dir(), "");
        
        // use curl if installed. Faster and probably more memory efficient.
        if (function_exists('curl_version'))
        {
            $fp = fopen($downloadedFilepath, 'w+');
            $ch = curl_init(str_replace(" ", "%20", $url));
            curl_setopt($ch, CURLOPT_TIMEOUT, 50);
            curl_setopt($ch, CURLOPT_FILE, $fp); 
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
            curl_exec($ch); 
            curl_close($ch);
            fclose($fp);
        }
        else
        {
            $content = file_get_contents($url);
            file_put_contents($downloadedFilepath, $content);
        }
        
        return $downloadedFilepath;
    }
1317412
public function doesFileExist($url) {
        // Setup connection
        $ch = curl_init($url);

        // We don't want to download the file, we just want to know if the file exists
        curl_setopt($ch, CURLOPT_NOBODY, true);

        // Execute cURL
        curl_exec($ch);

        // Get the HTTP status code
        $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

        // Close the connection
        curl_close($ch);

        // If status 200 the file exists, so return true in that case, otherwise false
        return $httpCode == 200;
    }
396081
protected function download($zipFile, $version = 'master')
    {
        switch ($version) {
            case 'develop':
                $filename = 'latest-develop.zip';
                break;
            case 'master':
                $filename = 'latest.zip';
                break;
        }

        $response = (new Client)->get('http://cabinet.laravel.com/'.$filename);

        file_put_contents($zipFile, $response->getBody());

        return $this;
    }
984002
public function download($url)
    {
        $options = array(
            'http' => array(
                'method' => 'GET',
                'header' => array(
                    'User-Agent: gender-api-client/1.0',
                    'Content-Type: application/json'
                ),
                'timeout' => 5
            ));

        if ($this->proxyHost) {
            $options['http']['proxy'] = 'tcp://'.$this->proxyHost.':'.$this->proxyPort;
            $options['http']['request_fulluri'] = true;
        }

        $context = stream_context_create($options);

        $response = @file_get_contents($url, false, $context);
        if ($response === false) {
            $lastError = error_get_last();
            if (is_array($lastError) && isset($lastError['message'])) {
                throw new NetworkErrorException($lastError['message']);
            }
        }

        return $response;
    }
42194
public function load(string $url): bool
    {
        $this->parsedfile = (new Parser($url))->get();

        return $this->preValidate();
    }
1080942
function downloadZip($fileName, $contentType = "application/zip")
    {
        if (!$this->isFinalized) {
            $this->finalize();
        }

        $headerFile = null;
        $headerLine = null;
        if (!headers_sent($headerFile, $headerLine)) {
            if ((ob_get_contents() === FALSE || ob_get_contents() == '') or die("\n<p><strong>Error:</strong> Unable to send file <strong>$fileName.epub</strong>. Output buffer contains the following text (typically warnings or errors):<br>" . ob_get_contents() . "</p>")) {
                if (ini_get('zlib.output_compression')) {
                    ini_set('zlib.output_compression', 'Off');
                }

                header("Pragma: public");
                header("Last-Modified: " . gmdate("D, d M Y H:i:s T"));
                header("Expires: 0");
                header("Accept-Ranges: bytes");
                header("Connection: close");
                header("Content-Type: " . $contentType);
                header('Content-Disposition: attachment; filename="' . $fileName . '";');
                header("Content-Transfer-Encoding: binary");
                header("Content-Length: " . $this->getArchiveSize());

                if (!is_resource($this->zipFile)) {
                    echo $this->zipData;
                } else {
                    rewind($this->zipFile);

                    while (!feof($this->zipFile)) {
                        echo fread($this->zipFile, $this->streamChunkSize);
                    }
                }
            }
            return TRUE;
        }
        return FALSE;
    }
42687
public function download($url, $handler, $path = null)
    {
        $result = $this->transferred = null;
        $this->hook->attach('file.download.before', $url, $handler, $path, $result, $this);

        if (isset($result)) {
            return $result;
        }

        $this->setHandler($handler);
        $this->setDestination($path);

        try {
            $temp = $this->downloadTempFile($url);
        } catch (Exception $ex) {
            return $ex->getMessage();
        }

        try {
            $this->validateHandler($temp);
        } catch (Exception $ex) {
            unlink($temp);
            return $ex->getMessage();
        }

        try {
            $result = $this->finalize($temp, $this->destination, false);
        } catch (Exception $ex) {
            $result = $ex->getMessage();
        }

        $this->hook->attach('file.download.after', $url, $handler, $temp, $result, $this);
        return $result;
    }