时间:2020-04-23来源:电脑系统城作者:电脑系统城
代码实例:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# -*- coding:utf-8 -*-import paramikoclass ssh(object): def __init__(self,host,port,user,password): self.host = host self.port = port self.user = user self.password = password self.ssh_client = paramiko.SSHClient() self.ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) self.ssh_client.connect(self.host, self.port, self.user, self.password) #执行指令返回文本字符串 def sftp_exec_command(self,command): arrconfiglist = [""] try: std_in, std_out, std_err = self.ssh_client.exec_command(command) for line in std_out: arrconfiglist.append(line.strip("\n")) del arrconfiglist[0] self.ssh_client.close() return arrconfiglist except Exception as e: print(e,"ssh ERROR") finally: self.ssh_client.close() #执行指令无返回 def sftp_exec_norecommand(self,command): try: self.ssh_client.exec_command(command) self.ssh_client.close() except Exception as e: print(e,"ssh ERROR") finally: self.ssh_client.close()'''在别的项目中被调用使用如下方法import ssh as sshif __name__ == '__main__': ssh.ssh().sftp_exec_command("--command information--")''''''if __name__ == '__main__': rect = ssh().sftp_exec_command("") print(rect)''' |
2023-03-17
python flask项目打包成docker镜像发布的过程2023-03-17
python调试模块ipdb详解2023-03-17
python使用openai生成图像的超详细教程python cron定时任务触发接口自动化巡检 apscheduler报错:Run time of job …… next run at: ……)” was missed by misfire_grace_time参数 找到任务超时的根本原因...
2023-03-15