Здесь код Paramiko для выполнения на удаленном Python AWS EC2:
import paramiko
sftp, transport= None, None, None
try:
if keyfilepath=='': keyfilepath= AWS_KEY_PEM
if keyfiletype == 'DSA': key = paramiko.DSSKey.from_private_key_file(keyfilepath)
else: key = paramiko.RSAKey.from_private_key_file(keyfilepath)
if contype== 'sftp' :
transport = paramiko.Transport((host, port))
transport.add_server_key(key)
transport.connect(None, username, pkey=key)
sftp = paramiko.SFTPClient.from_transport(transport)
if isprint : print('Root Directory :\n ', sftp.listdir())
return sftp
except Exception as e:
print('An error occurred creating client: %s: %s' % (e.__class__, e))
if sftp is not None: sftp.close()
if transport is not None: transport.close()
if ssh is not None: ssh.close()