0

I want to create a class (on a local computer) that connects via SSH to a remote one, opens python and runs the API calls (because only the remote computer can do the API calls). To run a script on the remote server is not good enough because I want to be able to "replicate" the API of the remote on the local machine, that's why I came up with the class idea that should:

  1. Start the SSH session
  2. run interactive api calls
  3. Close session when destroyed

I am using paramiko. This is what I tried and does not work:

import paramiko

client = paramiko.client.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname=hostname, username=username, password=password)
stdin, stdout, stderr = client.exec_command('ls -l')    # This command works great!
client.exec_command('python3')
_, stdout, _ = client.exec_command('print("hello world"')
client.exec_command('exit()')

It just runs but gets nothing, no output nor errors.

Basically my final goal will be to recreate the use of api.method(arg) I would run on the remote using myclass.method(arg) on my local machine.

J Agustin Barrachina
  • 3,501
  • 1
  • 32
  • 52

0 Answers0