Use this method to to download a file from the Telegram servers.
\param $telegram_file_path String File path on Telegram servers
\param $local_file_path String File path where save the file.
341599
public function downloadFile($telegram_file_path, $local_file_path)
    {
        $file_url = 'https://api.telegram.org/file/bot'.$this->bot_token.'/'.$telegram_file_path;
        $in = fopen($file_url, 'rb');
        $out = fopen($local_file_path, 'wb');

        while ($chunk = fread($in, 8192)) {
            fwrite($out, $chunk, 8192);
        }
        fclose($in);
        fclose($out);
    }
242268
def download(self, url, path, force_refetch=False, nocache=False):
        ''' 
        '''
        # Enable cache
        if os.path.isfile(path):
            getLogger().info("File exists, download task skipped -> {path}".format(path=path))
            return True
        try:
            # Open URL
            getLogger().info("Downloading: {url} -> {path}".format(url=url, path=path))
            response = self.fetch(url, force_refetch=force_refetch, nocache=nocache)
            if response is not None:
                # Download file
                local_file = open(path, "wb")
                local_file.write(response)
                local_file.close()
                # Finished
                return True
            else:
                return False
        except Exception as e:
            if hasattr(e, 'reason'):
                getLogger().exception('We failed to reach a server. Reason: %s' % (e.reason,))
            elif hasattr(e, 'code'):
                getLogger().exception("The server couldn't fulfill the request. Error code: {code}".format(code=e.code))
            else:
                # everything is fine
                getLogger().exception("Unknown error: %s" % (e,))
        return False
364478
def download_file(url, path, session=None, params=None):
    

    if url[0:2] == '//':
        url = 'https://' + url[2:]

    # Use a temporary file so that we don't import incomplete files.
    tmp_path = path + '.tmp'

    if session and params:
        r = session.get( url, params=params, stream=True )
    elif session and not params:
        r = session.get( url, stream=True )
    else:
        r = requests.get(url, stream=True)
    with open(tmp_path, 'wb') as f:
        total_length = int(r.headers.get('content-length', 0))
        for chunk in progress.bar(r.iter_content(chunk_size=1024), expected_size=(total_length / 1024) + 1):
            if chunk:  # filter out keep-alive new chunks
                f.write(chunk)
                f.flush()

    os.rename(tmp_path, path)

    return path
285430
def get(self, remote_file, local_file):
        
        sftp = self.get_sftp()
        try:
            sftp.get(remote_file, local_file)
        except Exception as e:
            logger.error('下载文件失败')
            logger.error('remote: %s, local: %s' % (remote_file, local_file))
            logger.error(e)
832381
public function uploadFile($file_path)
    {
        if ( ! is_file($file_path)) {
            throw new EasemobError('文件不存在', 404);
        }
        $url = $this->url.'chatfiles';

        $curl_file    = curl_file_create($file_path);
        $option       = [
            'file' => $curl_file,
        ];
        $access_token = $this->getToken();
        $header []    = 'Authorization: Bearer '.$access_token;

        return Http::postCurl($url, $option, $header, 'POST');
    }
604206
public function downloadFile($pathFrom, $pathTo)
    {
        if ( ! $remoteStream = @fopen("ssh2.sftp://{$this->ftpConnection}/{$pathFrom}", 'r')) {
            throw new SftpRemoteFileException("Unable to open remote: '{$pathFrom}'.");
        }

        // ensure that local file may be created
        if ( ! is_dir(dirname($pathTo))) {

            $this->files->makeDirectory(dirname($pathTo), static::DIRECTORY_CREATE_MODE, true, true);
        }

        if ( ! $localStream = @fopen($pathTo, 'w')) {

            throw new SftpLocalFileException("Unable to open local file: '{$pathTo}'.");
        }

        // write from our remote stream to our local stream

        if ($this->chunking) {

            $bytesRead = 0;

            while ( ! feof($remoteStream)) {

                $buffer = fread($remoteStream, $this->chunkSize);
                $bytesRead += strlen($buffer);

                if (fwrite($localStream, $buffer) === false) {

                    throw new SftpLocalFileException("Unable to write to local file: '{$pathTo}'.");
                }
            }

        } else {
            // just read the entire stream at once

            $buffer    = stream_get_contents($remoteStream);
            $bytesRead = strlen($buffer);

            if (fwrite($localStream, $buffer) === false) {

                throw new SftpLocalFileException("Unable to write to local file: '{$pathTo}'.");
            }

        }


        unset($buffer);

        fclose($localStream);
        fclose($remoteStream);

        event( new SshFileDownloaded(basename($pathFrom), $pathTo, $bytesRead) );

        return $bytesRead;
    }
84843
def scp_file_remote_to_local(self, remote_path, local_path):
        

        sshadd_command = [
            'ssh-add',
            '/Users/pyrat/.ssh/ubuntuNode'
        ]
        self.info_log(
            "executing command: %s" %
            ' '.join(sshadd_command)
        )
        p = subprocess.Popen(sshadd_command)
        p.wait()

        scp_command = [
            'scp',
            '-o',
            'StrictHostKeyChecking=no',
            '%s@%s:"%s"' %
            (
                self.browser_config.get('username'),
                self.get_ip(),
                remote_path
            ),
            local_path
        ]
        self.info_log(
            "executing command: %s" %
            ' '.join(scp_command)
        )
        p = subprocess.Popen(scp_command)
        p.wait()
934644
@Given("^I inbound copy '(.+?)' through a ssh connection to '(.+?)'$")
    public void copyFromRemoteFile(String remotePath, String localPath) throws Exception {
        commonspec.getRemoteSSHConnection().copyFrom(remotePath, localPath);
    }
1188379
def download(self, local, remote):
        
        self.sync(RemoteFile(remote, self.api), LocalFile(local))
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)
648689
def local_path(self, url, filename=None, decompress=False, download=False):
        
        if download:
            return self.fetch(url=url, filename=filename, decompress=decompress)
        else:
            filename = self.local_filename(url, filename, decompress)
            return join(self.cache_directory_path, filename)
640435
def get_remote_file(self, remote_path, local_path):
        
        sftp_client = self.transport.open_sftp_client()
        LOG.debug('Get the remote file. '
                  'Source=%(src)s. Target=%(target)s.' %
                  {'src': remote_path, 'target': local_path})
        try:
            sftp_client.get(remote_path, local_path)
        except Exception as ex:
            LOG.error('Failed to secure copy. Reason: %s.' %
                      six.text_type(ex))
            raise SFtpExecutionError(err=ex)
1100736
def download_file(self, remote, local):
        
        file = open(local, 'wb')
        try:
            self.download(remote, file)
        finally:
            file.close()
1207584
def put(self, local_path, path, atomic=True):
        
        self._connect()

        if self.sftp:
            self._sftp_put(local_path, path, atomic)
        else:
            self._ftp_put(local_path, path, atomic)

        self._close()
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;
    }
785804
def copy_submission_locally(self, cloud_path):
    
    local_path = os.path.join(self.download_dir, os.path.basename(cloud_path))
    cmd = ['gsutil', 'cp', cloud_path, local_path]
    if subprocess.call(cmd) != 0:
      logging.error('Can\'t copy submission locally')
      return None
    return local_path
995934
def download(url, localFileName=None, localDirName=None):
    
    localName = url2name(url)
    req = Request(url)
    r = urlopen(req)
    if r.info().has_key('Content-Disposition'):
        # If the response has Content-Disposition, we take file name from it
        localName = r.info()['Content-Disposition'].split('filename=')
        if len(localName) > 1:
            localName = localName[1]
            if localName[0] == '"' or localName[0] == "'":
                localName = localName[1:-1]
        else:
            localName = url2name(r.url)
    elif r.url != url:
        # if we were redirected, the real file name we take from the final URL
        localName = url2name(r.url)
    if localFileName:
        # we can force to save the file as specified name
        localName = localFileName
    if localDirName:
        # we can also put it in some custom directory
        if not os.path.exists(localDirName):
            os.makedirs(localDirName)
        localName = os.path.join(localDirName, localName)

    f = open(localName, 'wb')
    f.write(r.read())
    f.close()