Skip to content

Instantly share code, notes, and snippets.

@gremito
Created September 23, 2018 06:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gremito/2cc1e20a212c6d6121e5394fc746d23c to your computer and use it in GitHub Desktop.
Save gremito/2cc1e20a212c6d6121e5394fc746d23c to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
from paramiko import SSHClient, AutoAddPolicy
HOST = 'xx.xx.xx.xx'
PORT = 22
USER = 'user_name'
PASSWORD = 'user_password'
PRIVATE_KEY = '/Users/user_name/.ssh/id_rsa'
def upload(local_file, remote_file):
ssh = SSHClient()
ssh.set_missing_host_key_policy(AutoAddPolicy())
ssh.connect(
hostname=HOST,
port=PORT,
username=USER,
password=PASSWORD,
passphrase=PRIVATE_KEY)
sftp = ssh.open_sftp()
sftp.put(local_file, remote_file)
sftp.close()
ssh.close()
if __name__ == '__main__':
upload('/test.txt', '/home/user_name/test.txt')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment