久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

從 FTP 服務(wù)器上的 gz 文件中檢索數(shù)據(jù)而不在本地

Retrieve data from gz file on FTP server without writing it locally(從 FTP 服務(wù)器上的 gz 文件中檢索數(shù)據(jù)而不在本地寫入)
本文介紹了從 FTP 服務(wù)器上的 gz 文件中檢索數(shù)據(jù)而不在本地寫入的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我想檢索存儲(chǔ)在 FTP 服務(wù)器上的壓縮 gz 文件中的數(shù)據(jù),而不將文件寫入本地存檔.

I would like to retrieve the data inside a compressed gz file stored on an FTP server, without writing the file to the local archive.

目前我已經(jīng)完成了

from ftplib import FTP
import gzip

ftp = FTP('ftp.server.com')
ftp.login()  
ftp.cwd('/a/folder/')

fileName = 'aFile.gz'

localfile = open(fileName,'wb')
ftp.retrbinary('RETR '+fileName, localfile.write, 1024)

f = gzip.open(localfile,'rb')
data = f.read()

然而,這會(huì)將文件localfile"寫入當(dāng)前存儲(chǔ).

This, however, writes the file "localfile" on the current storage.

我試圖改變這個(gè)

from ftplib import FTP
import zlib

ftp = FTP('ftp.server.com')
ftp.login()  
ftp.cwd('/a/folder/')

fileName = 'aFile.gz'

data = ftp.retrbinary('RETR '+fileName, zlib.decompress, 1024)

但是,ftp.retrbinary 不輸出其回調(diào)的輸出.有沒有辦法做到這一點(diǎn)?

but, ftp.retrbinary does not output the output of its callback. Is there a way to do this?

推薦答案

一個(gè)簡單的實(shí)現(xiàn)是:

  • 將文件下載到內(nèi)存中類似文件的對象,例如 BytesIO;

將其傳遞給 fileobj 參數(shù)noreferrer">GzipFile 構(gòu)造函數(shù).

pass that to fileobj parameter of GzipFile constructor.

import gzip
from io import BytesIO
import shutil
from ftplib import FTP

ftp = FTP('ftp.example.com')
ftp.login('username', 'password')

flo = BytesIO()

ftp.retrbinary('RETR /remote/path/archive.tar.gz', flo.write)

flo.seek(0)

with open('archive.tar', 'wb') as fout, gzip.GzipFile(fileobj = flo) as gzip:
    shutil.copyfileobj(gzip, fout)

<小時(shí)>

以上將整個(gè) .gz 文件加載到內(nèi)存中.對于大文件來說什么是低效的.更智能的實(shí)現(xiàn)將改為流式傳輸數(shù)據(jù).但這可能需要實(shí)現(xiàn)一個(gè)智能的自定義類文件對象.


The above loads whole .gz file to a memory. What can be inefficient for large files. A smarter implementation would stream the data instead. But that would probably require implementing a smart custom file-like object.

另請參閱在 FTP 服務(wù)器上的 zip 文件中獲取文件名,而無需下載整個(gè)存檔.

這篇關(guān)于從 FTP 服務(wù)器上的 gz 文件中檢索數(shù)據(jù)而不在本地寫入的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Why I cannot make an insert to Python list?(為什么我不能插入 Python 列表?)
Insert a column at the beginning (leftmost end) of a DataFrame(在 DataFrame 的開頭(最左端)插入一列)
Python psycopg2 not inserting into postgresql table(Python psycopg2 沒有插入到 postgresql 表中)
list extend() to index, inserting list elements not only to the end(list extend() 索引,不僅將列表元素插入到末尾)
How to add element in Python to the end of list using list.insert?(如何使用 list.insert 將 Python 中的元素添加到列表末尾?)
TypeError: #39;float#39; object is not subscriptable(TypeError:“浮動(dòng)對象不可下標(biāo))
主站蜘蛛池模板: 91久久精品日日躁夜夜躁欧美 | 免费色视频 | 四虎色播 | 长河落日| 亚洲看片| 婷婷导航| 日本不卡一区 | 欧美久久一区二区 | 欧美另类激情 | 二色av | 精品视频免费 | 中文在线观看视频 | 黄色片网站视频 | 免费黄色网址在线观看 | 一本色道久久综合亚洲精品酒店 | 欧美精品在线看 | 成人免费毛片嘿嘿连载视频 | 精东影业一区二区三区 | www.日本在线观看 | 亚洲黄色av | 亚洲另类色图 | 午夜视频免费在线观看 | 人人综合 | 亚洲综合另类 | 久久综合久色欧美综合狠狠 | 国产一区二区在线播放 | 亚洲不卡 | www.狠狠 | 欧美精品www| 黄色a一级片| 国产精品2区 | 日韩国产一区二区 | 色噜噜狠狠一区二区三区果冻 | 91久久久久久久 | 中文字幕不卡视频 | 青青五月天 | h片免费看 | 日本欧美久久久久免费播放网 | 日韩欧美色图 | 久草视频观看 | 97操碰|