From c3534dff3cc86283753f7e469c504438b50d732c Mon Sep 17 00:00:00 2001 From: qiangyanwen <508737091@qq.com> Date: Mon, 26 Dec 2022 18:21:03 +0800 Subject: [PATCH] add test --- utils/ssh_client.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/utils/ssh_client.py b/utils/ssh_client.py index 3d6a66e..a99091a 100644 --- a/utils/ssh_client.py +++ b/utils/ssh_client.py @@ -17,6 +17,7 @@ class SSHConnection(object): self._client = None def __enter__(self): + print("客户端开始创建连接.....") transport = paramiko.Transport((self._host, self._port)) transport.connect(username=self._username, password=self._password) self._transport = transport @@ -32,7 +33,7 @@ class SSHConnection(object): self._sftp = paramiko.SFTPClient.from_transport(self._transport) self._sftp.put(local_path, remote_path) - def exec_command(self, command): + def command(self, command): if self._client is None: self._client = paramiko.SSHClient() self._client._transport = self._transport @@ -51,7 +52,9 @@ class SSHConnection(object): self._transport.close() if self._client: self._client.close() + print("客户端关闭已成功.....") with SSHConnection("47.96.135.132", 22, "root", "Qyw1994@520") as ssh: - ls = ssh.exec_command("ls -l") + ls = ssh.command("ls -l") + print(ls)