python connect sftp with key

Solutions on MaxInterview for python connect sftp with key by the best coders in the world

showing results for - "python connect sftp with key"
Julieta
04 Feb 2019
1import pysftp
2
3def upload_file(file_path):
4
5    private_key = "~/.ssh/your-key.pem"  # can use password keyword in Connection instead
6    srv = pysftp.Connection(host="your-host", username="user-name", private_key=private_key)
7    srv.chdir('/var/web/public_files/media/uploads')  # change directory on remote server
8    srv.put(file_path)  # To download a file, replace put with get
9    srv.close()  # Close connection