Lee un archivo en búfer desde FTP python
Estoy tratando de leer un archivo de un servidor FTP. El archivo es un.gz
expediente. Me gustaría saber si puedo realizar acciones en este archivo mientras el socket está abierto. Intenté seguir lo que se mencionó en dos preguntas de StackOverflow enLeer archivos sin escribir en el disco. yLeer archivos de FTP sin descargar pero no tuvo éxito.
Sé cómo extraer datos / trabajo en el archivo descargado, pero no estoy seguro de poder hacerlo sobre la marcha. ¿Hay alguna forma de conectarse al sitio, obtener datos en un búfer, posiblemente extraer algo y salir?
Al intentar StringIO me salió el error:
>>> from ftplib import FTP
>>> from StringIO import StringIO
>>> ftp = FTP('ftp://ftp.ncbi.nlm.nih.gov/pub/pmc/PMC-ids.csv.gz')
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
ftp = FTP('ftp://ftp.ncbi.nlm.nih.gov/pub/pmc/PMC-ids.csv.gz')
File "C:\Python27\lib\ftplib.py", line 117, in __init__
self.connect(host)
File "C:\Python27\lib\ftplib.py", line 132, in connect
self.sock = socket.create_connection((self.host, self.port), self.timeout)
File "C:\Python27\lib\socket.py", line 553, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
gaierror: [Errno 11004] getaddrinfo failed
Solo necesito saber cómo puedo obtener datos en alguna variable y hacer un bucle hasta que se lea el archivo de FTP.
Aprecio tu tiempo y ayuda. ¡Gracias!