久久久久久久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:“浮動對象不可下標)
主站蜘蛛池模板: 精品视频免费 | 99视频免费 | 日韩欧美网 | 岛国av在线免费观看 | 久久久久久久久国产成人免费 | 久久黄网| av影音资源| 亚洲不卡av在线 | 国产小视频在线 | 三级视频久久 | 日韩电影中文字幕 | 1204国产成人精品视频 | 中文字幕在线播放第一页 | 亚洲一区二区视频 | 亚洲精品乱码久久久久久久久 | 六月成人网 | 色免费在线视频 | 黄色一级大片在线免费看产 | 日韩视频精品 | 久草网视频 | 欧美日韩国产免费 | 国产日屁 | 91精品国产92| 国产精品久久久久aaaa樱花 | 国产精品久久久久久久久久久久 | 欧洲一区视频 | 日韩在线欧美 | 国产色网站 | 色综合久 | 欧美精品一区二区三区在线播放 | 亚洲一区中文 | 91国内产香蕉 | 久久久精品一区 | 91精品国产综合久久精品 | 国产精品日韩在线观看 | 国产高清精品一区二区三区 | 亚洲成人一级片 | 一级毛片网| 亚洲高清一区二区三区 | 日本中文字幕一区 | 欧美日韩在线电影 |