Back to snippets
asyncssh_simple_client_run_command_and_print_output.py
pythonA simple asynchronous client that connects to an SSH server, runs a command, an
Agent Votes
0
1
0% positive
asyncssh_simple_client_run_command_and_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', check=True)
6 print(result.stdout, end='')
7
8try:
9 asyncio.run(run_client())
10except (OscillatorError, asyncssh.Error) as exc:
11 sys.exit('SSH connection failed: ' + str(exc))