If $sLocal file is older than 24h or does not exist, tries to
download it from $sRemote and save it as $sLocal

@param string $sRemote the file
@param string $sLocal  the address of the remote source

@return mixed
960388
public function getRemoteCachePath($sRemote, $sLocal)
    {
        clearstatcache();
        if (file_exists($sLocal) && filemtime($sLocal) && filemtime($sLocal) > time() - 86400) {
            return $sLocal;
        }
        $hRemote = @fopen($sRemote, "rb");
        $blSuccess = false;
        if (is_resource($hRemote) && $hLocal = @fopen($sLocal, "wb")) {
            stream_copy_to_stream($hRemote, $hLocal);
            fclose($hRemote);
            fclose($hLocal);
            $blSuccess = true;
        } else {
            // try via fsockopen
            $aUrl = @parse_url($sRemote);
            if (!empty($aUrl["host"])) {
                $sPath = $aUrl["path"];
                if (empty($sPath)) {
                    $sPath = "/";
                }
                $sHost = $aUrl["host"];

                $hSocket = @fsockopen($sHost, 80, $iErrorNumber, $iErrStr, 5);
                if ($hSocket) {
                    fputs($hSocket, "GET " . $sPath . " HTTP/1.0\r\nHost: $sHost\r\n\r\n");
                    $headers = stream_get_line($hSocket, 4096, "\r\n\r\n");
                    if (($hLocal = @fopen($sLocal, "wb")) !== false) {
                        rewind($hLocal);
                        // does not copy all the data
                        // stream_copy_to_stream($hSocket, $hLocal);
                        fwrite($hLocal, stream_get_contents($hSocket));
                        fclose($hLocal);
                        fclose($hSocket);
                        $blSuccess = true;
                    }
                }
            }
        }
        if ($blSuccess || file_exists($sLocal)) {
            return $sLocal;
        }

        return false;
    }
1060021
protected function _expired( $sFilePath )
    {
        return (
            !is_file( $sFilePath ) or
            ( filemtime( $sFilePath ) - 1000 <= strtotime( sprintf( 'now - %d second', $this->getCacheTtl() ) ) )
        );
    }
598447
public function download($url)
    {
        $localPath = $this->makeLocalTemporaryPath();

        $url = $this->normalizeUrl($url);

        $this->downloadToTempLocalPath($url, $localPath);

        // Remove the query string if it exists, to make sure the extension is valid
        if (false !== strpos($url, '?')) {
            $url = explode('?', $url)[0];
        }

        $pathinfo = pathinfo($url);

        // If the file has no extension, rename the local instance with a guessed extension added.
        if (empty($pathinfo['extension'])) {
            $localPath = $this->renameLocalTemporaryFileWithAddedExtension($localPath, $pathinfo['basename']);
        }

        return $localPath;
    }
107715
private function download(RemotePackageEntity $remotePackage)
    {
        $temp = $this->app->make(VolatileDirectory::class);
        /* @var VolatileDirectory $temp */
        $zipFilename = $temp->getPath() . '/downloaded.zip';
        $this->httpClient->reset();
        $this->httpClient->setOptions([
            'storeresponse' => false,
            'outputstream' => $zipFilename,
        ]);
        $request = new Request();

        if (($header = (string) getenv('CT_REMOTEPACKAGE_HEADER')) &&
            $value = (string) getenv('CT_REMOTEPACKAGE_HEADER_VALUE')) {
            $request->getHeaders()->addHeaderLine($header, $value);
        }
        $request->setMethod('GET')->setUri($remotePackage->getArchiveUrl());
        $response = $this->httpClient->send($request);
        $this->httpClient->reset();
        $streamHandle = ($response instanceof \Zend\Http\Response\Stream) ? $response->getStream() : null;
        if (is_resource($streamHandle)) {
            fclose($streamHandle);
        }
        if ($response->getStatusCode() != 200) {
            $error = t('Failed to download package archive %s v%s: %s (%d)', $remotePackage->getHandle(), $remotePackage->getVersion(), $response->getReasonPhrase(), $response->getStatusCode());
            unset($temp);
            throw new DownloadException($error, $response->getStatusCode());
        }

        $contentEncodingHeader = $response->getHeaders()->get('Content-Encoding');
        if (!empty($contentEncodingHeader)) {
            $contentEncoding = trim((string) $contentEncodingHeader->getFieldValue());
            if ($contentEncoding !== '') {
                $decodedZipFilename = $temp->getPath() . '/downloaded-decoded.zip';
                switch (strtolower($contentEncoding)) {
                    case 'gzip':
                        $this->decodeGzip($zipFilename, $decodedZipFilename);
                        break;
                    case 'deflate':
                        $this->decodeDeflate($zipFilename, $decodedZipFilename);
                        break;
                    case 'plainbinary':
                    default:
                        $decodedZipFilename = '';
                        break;
                }
                if ($decodedZipFilename !== '') {
                    $temp->getFilesystem()->delete([$zipFilename]);
                    $zipFilename = $decodedZipFilename;
                }
            }
        }

        $temp->getFilesystem()->makeDirectory($temp->getPath() . '/unzipped');
        $this->zip->unzip($zipFilename, $temp->getPath() . '/unzipped');
        $temp->getFilesystem()->delete([$zipFilename]);

        return $temp;
    }
461142
public function download()
    {
        if ( ! $this->exists() ) {
            throw new FileExistException('Remote template does not exist');
        }

        try {
            $result = $this->getSoapClient()->DownloadTemplate(array(
                'filename' => basename($this->getName()) ));

            return base64_decode($result->DownloadTemplateResult);
        } catch ( SoapException $ex ) {
            throw new DownloadException('Error while downloading the remote template from Livedocx service' , $ex);
        }
    }
555341
function get($wsdl)
    {
        $filename = $this->createFilename($wsdl);
        if ($this->obtainMutex($filename, "r")) {
            // check for expired WSDL that must be removed from the cache
            if ($this->cache_lifetime > 0) {
                if (file_exists($filename) && (time() - filemtime($filename) > $this->cache_lifetime)) {
                    unlink($filename);
                    $this->debug("Expired $wsdl ($filename) from cache");
                    $this->releaseMutex($filename);

                    return NULL;
                }
            }
            // see what there is to return
            if (!file_exists($filename)) {
                $this->debug("$wsdl ($filename) not in cache (1)");
                $this->releaseMutex($filename);

                return NULL;
            }
            $fp = @fopen($filename, "r");
            if ($fp) {
                $s = implode("", @file($filename));
                fclose($fp);
                $this->debug("Got $wsdl ($filename) from cache");
            } else {
                $s = NULL;
                $this->debug("$wsdl ($filename) not in cache (2)");
            }
            $this->releaseMutex($filename);

            return (!is_null($s)) ? unserialize($s) : NULL;
        } else {
            $this->debug("Unable to obtain mutex for $filename in get");
        }

        return NULL;
    }
634707
def checkIfRemoteIsNewer(self, localfile):
        
        is_remote_newer = False
        if localfile.exists() and localfile.stat().st_size > 0:
            LOG.info("File exists locally, using cache")
        else:
            is_remote_newer = True
            LOG.info("No cache file, fetching entries")
        return is_remote_newer
1161692
public function checkFile($sFile)
    {
        $aCheckCache = \OxidEsales\Eshop\Core\Registry::getSession()->getVariable("checkcache");

        if (isset($aCheckCache[$sFile])) {
            return $aCheckCache[$sFile];
        }

        $blRet = true;
        if (!is_readable($sFile)) {
            $blRet = $this->urlValidate($sFile);
        }

        $aCheckCache[$sFile] = $blRet;
        \OxidEsales\Eshop\Core\Registry::getSession()->setVariable("checkcache", $aCheckCache);

        return $blRet;
    }
1224146
function GetLastModifiedDate($remotepath) 
	{
		$curl = curl_init($remotepath);
		curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, ET_Util::shouldVerifySslPeer($this->sslVerifyPeer));
		curl_setopt($curl, CURLOPT_NOBODY, true);
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($curl, CURLOPT_FILETIME, true);

		if (!empty($this->proxyHost)) {
			curl_setopt($curl, CURLOPT_PROXY, $this->proxyHost);
		}
		if (!empty($this->proxyPort)) {
			curl_setopt($curl, CURLOPT_PROXYPORT, $this->proxyPort);
		}
		if (!empty($this->proxyUserName) && !empty($this->proxyPassword)) {
			curl_setopt($curl, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
			curl_setopt($curl, CURLOPT_PROXYUSERPWD, $this->proxyUserName.':'.$this->proxyPassword);
		}

		$result = curl_exec($curl);
		
		if ($result === false) {
			throw new Exception(curl_error($curl)); 
		}
		
		return curl_getinfo($curl, CURLINFO_FILETIME);
	}
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;
        }
    }
135533
public function getThumbnailUrl($sFile = '', $iThumbSize = null)
    {
        if ($sFile) {
            if (!$iThumbSize) {
                $iThumbSize = $this->_iDefaultThumbnailSize;
            }

            $sThumbName = $this->getThumbName($sFile, $iThumbSize);

            if ($sThumbName) {
                return $this->getMediaUrl('thumbs/' . $sThumbName);
            }
        } else {
            return $this->getMediaUrl('thumbs/');
        }

        return false;
    }
1022318
public static function downloadFile($src, $dst)
    {
        $result = false;

        $fileHandler = @fopen($dst, 'w');
        if (!is_resource($fileHandler)) {
            return $result;
        }

        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $src);
        curl_setopt($curl, CURLOPT_FILE, $fileHandler);
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
        $result = curl_exec($curl);
        curl_close($curl);
        fclose($fileHandler);

        return $result;
    }
1153278
public function getImageUrl($sFile = null, $bSsl = null)
    {
        if ($sFile) {
            $sValue = $this->getConfig()->getImageUrl($this->isAdmin(), $bSsl, null, $sFile);
        } elseif (($sValue = $this->getViewConfigParam('imagedir')) === null) {
            $sValue = $this->getConfig()->getImageUrl($this->isAdmin(), $bSsl);
            $this->setViewConfigParam('imagedir', $sValue);
        }

        return $sValue;
    }
1364634
public function objectLocalPath($sBucket, $sFilename)
    {
        $sPath = $this->getPath() . $sBucket . '/' . $sFilename;

        if (is_file($sPath)) {
            return $sPath;
        } else {
            $this->setError('Could not find a valid local path for object ' . $sBucket . '/' . $sFilename);
            return false;
        }
    }
373411
static function download($reqst = '')
    {
        //checando a existencia do arquivo solicitado
        $reqst = static::fileExists($reqst);
        if($reqst == false) return false;

        //gerando header apropriado
        include static::$config.'mimetypes.php';
        $ext = end((explode('.', $reqst)));
        if (!isset($_mimes[$ext])) $mime = 'text/plain';
        else $mime = (is_array($_mimes[$ext])) ? $_mimes[$ext][0] : $_mimes[$ext];

        //get file
        $dt = file_get_contents($reqst);

        //download
        ob_end_clean();
        ob_start('ob_gzhandler');

        header('Vary: Accept-Language, Accept-Encoding');
        header('Content-Type: ' . $mime);
        header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 31536000) . ' GMT');
        header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($reqst)) . ' GMT');
        header('Cache-Control: must_revalidate, public, max-age=31536000');
        header('Content-Length: ' . strlen($dt));
        header('Content-Disposition: attachment; filename='.basename($reqst)); 
        header('ETAG: '.md5($reqst));
        exit($dt);
    }
808362
function get_file($srcpath, $localpath) {

        $localpath = $this->utf_decode_path($localpath);

        $handle = fopen($localpath, 'wb');
        if ($handle) {
            $unused = '';
            $ret = $this->get($srcpath, $unused, $handle);
            fclose($handle);
            if ($ret) {
                return true;
            }
        }
        return false;
    }
105125
protected function moveTemporaryFile($strFile, $strDestination)
    {
        if (!is_file(TL_ROOT . '/' . $strFile)) {
            return '';
        }

        // Do not store the file
        if (!$this->arrConfiguration['storeFile']) {
            return $strFile;
        }

        // The file is not temporary
        if (stripos($strFile, $this->strTemporaryPath) === false) {
            return $strFile;
        }

        $strNew = $strDestination . '/' . basename($strFile);

        // Do not overwrite existing files
        if ($this->arrConfiguration['doNotOverwrite']) {
            $strNew = $strDestination . '/' . $this->getFileName(basename($strFile), $strDestination);
        }

        $blnRename = \Files::getInstance()->rename($strFile, $strNew);

        \Files::getInstance()->chmod($strNew, \Config::get('defaultFileChmod'));

        // Add the file to Dbafs
        if ($this->arrConfiguration['addToDbafs'] && $blnRename) {
            $objModel = \Dbafs::addResource($strNew);

            if ($objModel !== null) {
                $strNew = $objModel->uuid;
            }
        }

        return $strNew;
    }