title: Read a file in buffer from FTP python
body: <p>I am trying to read a file from an FTP server. The file is a <code>.gz</code> file. I would like to know if I can perform actions on this file while the socket is open. I tried to follow what was mentioned in two StackOverflow questions on <a href="https://stackoverflow.com/questions/11208957/is-it-possible-to-read-ftp-files-without-writing-them-using-python">reading files without writing to disk</a> and <a href="https://stackoverflow.com/questions/7690320/how-to-read-files-from-ftp-without-download-them">reading files from FTP without downloading</a> but was not successful.</p>
  
  <p>I know how to extract data/work on the downloaded file but I'm not sure if I can do it on the fly. Is there a way to connect to the site, get data in a buffer, possibly do some data extraction and exit?</p>
  
  <p>When trying StringIO I got the error:</p>
  
  <pre><code>&gt;&gt;&gt; from ftplib import FTP
  &gt;&gt;&gt; from StringIO import StringIO
  &gt;&gt;&gt; ftp = FTP('ftp://ftp.ncbi.nlm.nih.gov/pub/pmc/PMC-ids.csv.gz')
  
  Traceback (most recent call last):
  File "&lt;pyshell#2&gt;", line 1, in &lt;module&gt;
  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
  </code></pre>
  
  <p>I just need to know how can I get data into some variable and loop on it until the file from FTP is read.</p>
  
  <p>I appreciate your time and help. Thanks! </p>