[Python]paramiko实时获取命令执行输出及sftp上传
来源:互联网 发布:rt809h编程器最新消息 编辑:程序博客网 时间:2024/05/15 08:10
import paramiko, osclass preExecute(): def __init__(self, _hostip, _username, _password): self.__channel = group self.__hostip = _hostip self.__username = _username self.__password = _password self.__sshclient = self.ssh_connect(self.__hostip, self.__username, self.__password) self.__currentpath = os.getcwd() self.__destdir = "/opt/uniagentdfr/" self.__sftpclient = None def __del__(self): self.__sshclient.close() try: self.__sftpclient.close() except: pass def run(self): self.execute('mkdir -p '+self.__destdir) filename = self.__currentpath+"/controller/static/controller/module.zip" self.sftp_put(filename, self.__destdir + "module.zip") self.execute("cd "+self.__destdir+ ";") self.execute("touch /opt/uniagentdfr/aaaaa;") self.execute("unzip -o /opt/uniagentdfr/module.zip -d /opt/uniagentdfr/;") self.execute("chmod -R 755 *;") self.__del__(); def ssh_connect(self,_host, _username, _password): try: _ssh_fd = paramiko.SSHClient() _ssh_fd.set_missing_host_key_policy(paramiko.AutoAddPolicy()) _ssh_fd.connect(_host, username=_username, password=_password) return _ssh_fd except Exception as e: print('ssh %s@%s:passwd %s, error message is %s' % (_username, _host,_password, e)) def sftp_open(self): if self.__sftpclient is None: self.__sftpclient = self.__sshclient.open_sftp() return ; def sftp_put(self, _put_from_path, _put_to_path): self.sftp_open() return self.__sftpclient.put(_put_from_path, _put_to_path) def sftp_get(self,_get_from_path, _get_to_path): self.__sftpclient = self.sftp_open(self.__sshclient) self.__sftpclient.get(_get_from_path, _get_to_path) self.__sftpclient.close() self.__sftpclient = None return ; def execute(self, command): try: stdin, stdout, stderr = self.__sshclient.exec_command(command) for line in stdout: print(line.strip("\n")) except Exception as e: print("execute command %s error, error message is %s" % (command, e)) return ""
阅读全文
0 0
- [Python]paramiko实时获取命令执行输出及sftp上传
- python paramiko模块实现远程文件上传文件, 执行命令
- python paramiko利用sftp上传目录到远程
- [Python/自动化运维] 利用Paramiko模块执行批量上传/下载/执行命令/查看服务器列表
- python paramiko链接linux执行命令操作
- Python执行命令行命令并获取输出
- Django中paramiko使用密钥执行命令和上传文件
- paramiko 远程执行命令
- python paramiko 通过密钥文件登陆ssh和听过sftp上传文件
- (转)python中paramiko ssh sftp使用
- Python paramiko模块之SSH SFTP
- Python + Paramiko实现sftp文件上传下载
- python paramiko模块实现sftp上传下载文件
- Python-远程管理-Paramiko实现ssh&sftp
- Python paramiko SFTP协议上传下载文件
- Python + Paramiko实现sftp文件上传下载
- python模块paramiko的上传下载和远程执行命令方法
- python利用paramiko连接远程服务器执行命令
- 偏函数
- 关于AndroidStudio3.0 升级你可能遇到的事
- Javaweb开发为什么需要分前后端,放弃原生JSP
- FZU 2030
- 51Nod 1284 2 3 5 7的倍数
- [Python]paramiko实时获取命令执行输出及sftp上传
- juniper:opencontrail/contrail 作为SDN解决方案
- java动态代理原理源码解析(jdk8)
- STL 常用库简介
- TabLayout设置指示器长度
- MySQL表结构,表空间,段,区,页,MVCC
- poj 2923
- Linux目录结构与常用命令
- Linux文件操作 create/open/close/write/read函数