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

從 FTP 服務器上的 gz 文件中檢索數據而不在本地

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

問題描述

我想檢索存儲在 FTP 服務器上的壓縮 gz 文件中的數據,而不將文件寫入本地存檔.

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.

目前我已經完成了

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()

然而,這會將文件localfile"寫入當前存儲.

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

我試圖改變這個

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 不輸出其回調的輸出.有沒有辦法做到這一點?

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

推薦答案

一個簡單的實現是:

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

將其傳遞給 fileobj 參數noreferrer">GzipFile 構造函數.

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)

<小時>

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


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 服務器上的 zip 文件中獲取文件名,而無需下載整個存檔.

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

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

相關文檔推薦

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:“浮動對象不可下標)
主站蜘蛛池模板: 91免费在线看 | 天堂在线1| 成人国产精品免费观看 | av毛片免费 | 欧美精品久久久久久 | 日韩在线电影 | 精品自拍视频在线观看 | 91av在线不卡 | 欧美日韩第一页 | 欧美成人a∨高清免费观看 91伊人 | 一级黄色片美国 | 操皮视频 | 麻豆视频国产在线观看 | av综合站| 国产高清在线精品一区二区三区 | 日韩欧美国产精品一区二区三区 | 国产精品日韩欧美一区二区三区 | 一区网站 | 国产精品久久久99 | 欧美二区在线 | 日韩国产在线 | 亚洲永久精品国产 | 国产日韩欧美中文 | 成人在线精品视频 | 国产最好的av国产大片 | 中文字幕乱码一区二区三区 | 国产欧美精品一区 | 欧美一区二区三区四区视频 | 亚洲精品久久久一区二区三区 | 婷婷精品 | 看a网站 | 国产精品久久久久久久久免费软件 | 97精品久久| 亚洲欧美在线视频 | 色视频网站 | 999久久久国产精品 欧美成人h版在线观看 | 亚洲精品一区二区三区中文字幕 | 日本三级网 | 91精品国产综合久久福利软件 | 日韩午夜电影在线观看 | av中文字幕在线 |