简体   繁体   English

如何从FTP服务器读取gzip压缩文件?

[英]How to read gzipped file from FTP server?

I want to read file from public FTP server, and can't seem to figure how to use gzip and urllib efficiently, without explicitely downloading the file then opening it with gzip.open() . 我想从公共FTP服务器读取文件,并且似乎无法弄清楚如何有效地使用gzip和urllib,而无需显式下载文件,然后使用gzip.open()打开它。 Is there other way possible at all? 还有其他可能吗?

For example " ftp://ftp.server.com/pub/data/archive.gz " is link I got. 例如,“ ftp://ftp.server.com/pub/data/archive.gz ”是我得到的链接。 What is the right way to read the contents from this file in Python? 在Python中从此文件读取内容的正确方法是什么?


Edit: 编辑:

So I ended using: 所以我结束了使用:

g = gzip.open(urllib.urlretrieve(url)[0])

Argument to gzip.open() this way is temp file downloaded from url path, and g is now like regular file object representing archive contents gzip.open()这种方式是从URL路径下载的临时文件,而g现在就像表示存档内容的常规文件对象一样

可能的工作是将其读取到内存中,然后将其解压缩,问题是最终将使用大量的内存,因此最好下载而不是将其下载到内存中并从那里进行操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM