title: How to read contents and attributes of files in remote SFTP server using pysftp/Paramiko
body: <p>I am using below code to get list of file objects  in list from two different nodes.
  My purpose is to get the file metadata and compare the files later. But using <code>filelist = mysftp.listdir()</code>, I am only getting the filenames and unable to fetch something like <code>file.content</code> or <code>file.size</code>.</p>
  <p>For testing purpose I am using only one EC2 node and calling it parallel.</p>
  <pre><code>import pysftp
  import itertools 
  from multiprocessing import Process, Pool
  
  # Connect/ssh to an instance
  
  file_list = []
  
  def readFileNode(host):
      try:
          cnopts = pysftp.CnOpts()
          cnopts.hostkeys = None
  
          mysftp = pysftp.Connection(
              host=&quot;3.93.XX.XX&quot;,
              username=&quot;ubuntu&quot;,
              private_key=&quot;/Users/test.pem&quot;,
              cnopts=cnopts,
          )
  
          mysftp.cwd(&quot;/home/ubuntu/demo&quot;)
          filelist = mysftp.listdir()
  
      except Exception:
          print(e)
  
      return filelist
  
  if __name__ == '__main__':
      p = Pool(2)
      result = p.map(readFileNode, ['3.93.XX.XX', '3.93.XX.XX'])
      print(result)  
  
      print(result[0])
      print(result[1])
      fileList1=[]
      fileList2=[]
      fileList1=list[0]
      fileList2=list[1]
      
      for (a, b) in zip(fileList1,fileList2):
         print (a, b)
         #compare two files and also get the file metadata
  </code></pre>
  <p>I have files from both the nodes in <code>result[0]</code> and <code>result[1]</code>.
  But, I want to get the file objects so that I can compare them and list down the attributes. i.e. something like <code>file.size</code>, compare <code>file1.content</code> with <code>file2.content</code>. Where <code>file1</code> is from node1 and <code>file2</code> is from node2.</p>