使用 paramiko 检查是否存在与远程主机的连接

发布于 2024-08-12 12:56:59 字数 155 浏览 3 评论 0原文

我使用 paramiko.SSHClient() 的单个对象在远程计算机上执行命令。当我使用 ssh.exec_command(cmd) 时,与远程主机的连接丢失,ssh.exec_command 挂起。

有没有办法在 ssh.exec_command() 之前检查连接是否存在?

I'm using single object of paramiko.SSHClient() for executing a command on a remote machine. When I use ssh.exec_command(cmd), and the connection to remote host is lost, ssh.exec_command hangs up.

Is there a way to check for connection existence before ssh.exec_command()?

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

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

发布评论

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

评论(2

半葬歌 2024-08-19 12:56:59

如果您有长时间运行的 SSH 连接,您可能需要使用 Keep Alive 参数通过 Transport.set_keepalive

If you have a long running SSH connection, you may want to use the Keep Alive parameter via Transport.set_keepalive.

闻呓 2024-08-19 12:56:59

作为另一种可能性,execnet 可能会起作用。它包装了命令行 ssh 命令,所以它绝对不是 paramiko 方法......只是一个。

As an alternate possibility, maybe execnet would work. It wraps the command line ssh command instead, so it's definitely not the paramiko approach... just a though.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文