title: Read GZIP text file from remote server over SFTP
body: <p>I have many large text files on a remote server that I would like to read without unzipping programmatically</p>
  
  <p>I have functionality working for reading a non-GZIP text file from the remote server as well as reading a GZIP text file locally. I am not sure how to combine the two or if it is possible</p>
  
  <p>Below are the individually working pieces of code:</p>
  
  <pre><code>from contextlib import closing
  from fabric.network import connect
  from fabric import state
  import gzip
  
  # This successfully reads a non-GZIP text file from user@host:filePath
  with closing(connect("user", "host", "port", None)) as ssh:
      with closing(ssh.open_sftp()) as sftp:
          with closing(sftp.open("filePath")) as f:
              for line in f:
                  print line
  
  # This successfully reads a GZIP text file locally
  with gzip.open("fileName", "r") as f:
      for line in f:
          print line
  </code></pre>