title: How to scp in Python?
body: <p>What's the most pythonic way to scp a file in Python?  The only route I'm aware of is </p>
  
  <pre><code>os.system('scp "%s" "%s:%s"' % (localfile, remotehost, remotefile) )
  </code></pre>
  
  <p>which is a hack, and which doesn't work outside Linux-like systems, and which needs help from the Pexpect module to avoid password prompts unless you already have passwordless SSH set up to the remote host.</p>
  
  <p>I'm aware of Twisted's <code>conch</code>, but I'd prefer to avoid implementing scp myself via low-level ssh modules.</p>
  
  <p>I'm aware of <code>paramiko</code>, a Python module that supports SSH and SFTP; but it doesn't support SCP.</p>
  
  <p>Background: I'm connecting to a router which doesn't support SFTP but does support SSH/SCP, so SFTP isn't an option.</p>
  
  <p><strong>EDIT</strong>:
  This is a duplicate of <a href="https://stackoverflow.com/questions/68335/how-do-i-copy-a-file-to-a-remote-server-in-python-using-scp-or-ssh">How to copy a file to a remote server in Python using SCP or SSH?</a>.  <strong>However</strong>, that question doesn't give an scp-specific answer that deals with keys from within Python.  I'm hoping for a way to run code kind of like</p>
  
  <pre><code>import scp
  
  client = scp.Client(host=host, user=user, keyfile=keyfile)
  # or
  client = scp.Client(host=host, user=user)
  client.use_system_keys()
  # or
  client = scp.Client(host=host, user=user, password=password)
  
  # and then
  client.transfer('/etc/local/filename', '/etc/remote/filename')
  </code></pre>