-
Notifications
You must be signed in to change notification settings - Fork 166
Closed
Description
I'm trying to establish an interactive SSH shell using the following code:
import asyncio, asyncssh, sys
async def run_client():
async with asyncssh.connect(
HOST, port=PORT, username=USER, password=PASSWORD,
known_hosts=None) as conn:
stdin, stdout, stderr = await conn.open_session()
# Try to get the welcoming message and shell prompt
welcome = await stdout.read(1024)
print(welcome)
loop = asyncio.get_event_loop()
try:
loop.run_until_complete(run_client())
except (OSError, asyncssh.Error) as exc:
sys.exit('SSH connection failed: ' + str(exc))
However, when running this program, the stdout.read(1024) never returns. I can obtain the desired behavior using paramiko with the following code:
from paramiko import SSHClient, AutoAddPolicy
with SSHClient() as client:
client.set_missing_host_key_policy(AutoAddPolicy())
client.connect(hostname, port, username, password)
with client.invoke_shell() as chan:
chan.settimeout(2)
## wait until some data is available
while not channel.recv_ready():
time.sleep(0.3)
## get the data
welcome = b""
while channel.recv_ready():
welcome += channel.recv(2**13)
time.sleep(delay)
print(welcome.decode("utf-8"))
Metadata
Metadata
Assignees
Labels
No labels