-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Closed
Description
Using an instance of Channel received from somewhere without a reference to SSHClient being explicitly kept (to prevent it from being garbage collected) sometimes gives unexpected results. For instance, a call to exec_command() raises an exception about the channel being closed, while recv_exit_status() just returns -1.
Here's a synthetic test case.
import paramiko
def exec_remote_command(command, host, username=None, password=None):
channel = _exec_remote_command(command, host, username=username, password=password)
return channel.recv_exit_status()
def _exec_remote_command(command, host, username=None, password=None):
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.MissingHostKeyPolicy())
client.connect(host, username=username, password=password)
channel = client.get_transport().open_session()
channel.exec_command(command)
return channel
if __name__ == '__main__':
print exec_remote_command('ls', '127.0.0.1') # prints -1Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels