title: How to recursively Copy a remote directory in Python
body: <p>I am  a novice in Python Programming. I am actually to trying to write a simple code ( Not in OOPs) to copy a directory recursively from the remote machine. Something which SCP does. I have tried refering this link  <a href="https://gist.github.com/johnfink8/2190472" rel="nofollow">https://gist.github.com/johnfink8/2190472</a> , However this looks too complicated, whereas I just need to login to remote host using username and password and copy  the required directories. I'm actually trying with following code, where this is only meant for copying files . and Errors with :::</p>
  
  <blockquote>
    <p>Copying Files From Remote Node Traceback (most recent call last):<br>
    File "./test.py", line 34, in 
        SCP(host,username,password)   File "./test.py", line 31, in SCP
        sftp.get(sourcepath,destinationpath)   File "/usr/lib/python2.7/site-packages/paramiko/sftp_client.py", line 719,
    in get
        with open(localpath, 'wb') as fl: IOError: [Errno 21] Is a directory: '/etc'</p>
  </blockquote>
  
  <pre><code>#!/usr/bin/python
  
  import paramiko
  
  
  
  nbytes = 4096
  host = '192.168.1.10'
  port = 22
  username = 'root'
  password = 'root'
  sourcepath = '/opt'
  destinationpath = '/etc'
  
  
  def SCP(host,username,password):
          scp = paramiko.Transport((host,port))
          scp.connect(username=username,password=password)
          sftp = paramiko.SFTPClient.from_transport(scp)
          sftp.get(sourcepath,destinationpath)
  
  print ("Copying Files From Remote Node")
  SCP(host,username,password)
  </code></pre>
  
  <p>Thanks
  Amit</p>