Petit exemple avec paramiko
import paramiko
import os
client = paramiko.SSHClient()
client._policy = paramiko.WarningPolicy()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_config = paramiko.SSHConfig()
user_config_file = os.path.expanduser("/home/nsukami/.ssh/config")
if os.path.exists(user_config_file):
with open(user_config_file) as f:
ssh_config.parse(f)
options = ssh_config.lookup('phobos')
cfg = {'hostname': options['hostname'],
'username': options["user"],
'port': int(options['port'])}
if 'proxycommand' in options:
cfg['sock'] = paramiko.ProxyCommand(user_config['proxycommand'])
client.connect(**cfg)
sftp = client.open_sftp()
sftp.put('fabfile.py','/home/patrick/fabfile.py' )
print ("copied successfully!")
sftp.get('/webapps/wappa/dummy.txt', './dummy.txt')
print("retrieved successfully")
sftp.close()
client.close()
exit()