title: Upload file via SFTP with Python
body: <p>I wrote a simple code to upload a file to a SFTP server in Python. I am using Python 2.7.</p>
  <pre><code>import pysftp
  
  srv = pysftp.Connection(host=&quot;www.destination.com&quot;, username=&quot;root&quot;,
  password=&quot;password&quot;,log=&quot;./temp/pysftp.log&quot;)
  
  srv.cd('public') #chdir to public
  srv.put('C:\Users\XXX\Dropbox\test.txt') #upload file to nodejs/
  
  # Closes the connection
  srv.close()
  </code></pre>
  <p>The file did not appear on the server. However, no error message appeared. What is wrong with the code?</p>
  <p>I have enabled logging. I discovered that the file is uploaded to the root folder and not under <code>public</code> folder. Seems like <code>srv.cd('public')</code> did not work.</p>