如何在Python Paramiko中运行Echo命令

发布于 2025-02-02 17:51:04 字数 110 浏览 3 评论 0原文

我需要在python paramiko.client.sshclient()中运行echo命令,为此我可以导入任何库。我尝试了paramiko.transport也无法正常工作。

I need do run the echo command in the python paramiko.client.SSHClient() For this can I import any libraries. I tried paramiko.transport also not working.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

幽梦紫曦~ 2025-02-09 17:51:04

创建sshclient对象后,请使用exec_command方法将命令分配给客户端,例如

client = paramiko.SSHClient()
... # set client object as needed and connect to SSHClient
command = "ls -l"  # or echo
# execute command and handle output
stdin, stdout, stderr = client.exec_command(command)
print(stdout.read().decode("utf-8"))
print(f"status_code={stdout.channel.recv_exit_status()}")
print(stderr.read().decode("utf-8"))

After creating a SSHClient object use the exec_command method to dispatch a command to the client, e.g.

client = paramiko.SSHClient()
... # set client object as needed and connect to SSHClient
command = "ls -l"  # or echo
# execute command and handle output
stdin, stdout, stderr = client.exec_command(command)
print(stdout.read().decode("utf-8"))
print(f"status_code={stdout.channel.recv_exit_status()}")
print(stderr.read().decode("utf-8"))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文