Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import paramiko
- import time
- import os
- def touch(path):
- with open(path, 'a'):
- os.utime(path, None)
- ssh = paramiko.SSHClient()
- ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- ssh.connect('ip', port=port, username='USER', password='PASS',
- key_filename='OPTIONAL Address to private Key')
- baseCommand = "command"
- stdin, stdout, stderr = ssh.exec_command('some command')
- print(stdout.readlines())
- stdin, stdout, stderr = ssh.exec_command(baseCommand + 'ls')
- print(stdout.readlines())
- #for copy file
- localpath = "local paths" + time.strftime("%Y-%m-%d-%H-%M-%S") + ".sql"; # add a date name for file
- remotepath = "remote path"
- touch(localpath);
- sftp.get(remotepath, localpath) # download the file
- sftp.close()
- ssh.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement