Created
September 23, 2018 06:10
-
-
Save gremito/2cc1e20a212c6d6121e5394fc746d23c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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