久久久久久久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:“浮動對象不可下標)
主站蜘蛛池模板: 国产羞羞视频在线观看 | 91av视频在线免费观看 | 久久综合色综合 | 91传媒在线观看 | 精品视频亚洲 | 国产一区二区三区四区在线观看 | 精品国产成人 | 欧洲成人免费视频 | 最新日韩欧美 | 99久久亚洲 | 成人性视频免费网站 | 欧美午夜影院 | 日韩a视频 | 午夜小电影 | 久久精品日产第一区二区三区 | 在线不卡av| 欧美涩 | 天堂三级 | av在线伊人 | 综合五月 | 精品日韩一区二区 | 国际精品鲁一鲁一区二区小说 | 91精品综合久久久久久五月天 | 中文字幕精品视频 | 久草精品视频 | 免费黄色a视频 | 亚洲国产中文字幕 | 天天天久久久 | 亚洲欧美综合网 | 久久国产一区二区 | 亚洲视频二区 | 久久在线| 自拍偷拍中文字幕 | 免费亚洲婷婷 | 国产精品亚洲一区二区三区在线观看 | 成人在线不卡 | 九色在线视频 | 亚洲成人在线视频播放 | 欧美精品在线一区 | 一区二区国产精品 | 亚洲网址在线观看 |