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