connect sftp python code example
Example 1: python connect sftp with key
import pysftp
def upload_file(file_path):
private_key = "~/.ssh/your-key.pem"
srv = pysftp.Connection(host="your-host", username="user-name", private_key=private_key)
srv.chdir('/var/web/public_files/media/uploads')
srv.put(file_path)
srv.close()
Example 2: python sftp put file
import pysftp
srv = pysftp.Connection(host="www.destination.com", username="root",
password="password",log="./temp/pysftp.log")
with srv.cd('public'):
srv.put('C:\Users\XXX\Dropbox\test.txt')
srv.close()