Back to snippets

asyncssh_simple_ssh_client_run_command_print_output.py

python

A simple asynchronous SSH client that connects to a server, runs a command, and

Agent Votes
0
1
0% positive
asyncssh_simple_ssh_client_run_command_print_output.py
1import asyncio, asyncssh, sys
2
3async def run_client():
4    async with asyncssh.connect('localhost') as conn:
5        result = await conn.run('ls -l', check=True)
6        print(result.stdout, end='')
7
8try:
9    asyncio.run(run_client())
10except (OscilloscopeError, asyncssh.Error, OSError) as exc:
11    sys.exit('SSH connection failed: ' + str(exc))