Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import paramiko
- import getpass
- import os
- try:
- from credentials import SERVER_IP
- from credentials import ADMIN_LOGIN
- from credentials import ADMIN_PASSWORD
- except ImportError:
- raise ImportError("Could not find credentials. Make sure credentials.py is there.")
- def upload_files_from_local_directory(ssh, local_path, remote_path):
- sftp_client= ssh.open_sftp()
- for file in os.listdir(local_path):
- file_remote = remote_path + file
- file_local = local_path + file
- print(file_local + ">>>" + file_remote)
- sftp_client.put(file_local,file_remote)
- sftp_client.close()
- def download_files_from_remote_directory(ssh, local_path, remote_path):
- sftp_client= ssh.open_sftp()
- for file in os.listdir(local_path):
- file_remote = remote_path + file
- file_local = local_path + file
- print(file_remote + ">>>" + file_local)
- sftp_client.get(file_remote,file_local)
- sftp_client.close()
- def ssh_command(ssh,command):
- stdin, stdout, stderr = ssh.exec_command(command)
- print(stdout.read())
- def ssh_connect(host, user, key):
- try:
- ssh = paramiko.SSHClient()
- print('Calling paramiko')
- ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- ssh.connect(hostname=host, username=user, password=key)
- return ssh
- except Exception as e:
- print('Connection Failed')
- print(e)
- if __name__=='__main__':
- user = ADMIN_LOGIN
- key = ADMIN_PASSWORD
- host = SERVER_IP
- ssh_connect(host, user, key)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement