#!/usr/bin/env python #-*-coding:UTF-8-*- """ @Item : v1.0 @Author : ShengWangQiang @Group : System @Date : 2015-01-28 @E-mail : swq.499809608@hotmail.com @Funtion: """ import sys,time,os,traceback,commands, import paramiko, class Remote(object): def __init__(self): version = 'v0.1' self.users = 'root' self.passwd = "1234567890" self.port = 22 def log(self,info): files = open('/tmp/deploy.log','a') try: files.write('[%s]: %s \n' %(time.ctime(),info)) except IOError: files.close() files.close() def cmds(self,host,comm): try: print comm client = paramiko.Transport((host,int(self.port))) client.connect(username=self.users,password=self.passwd) chan = client.open_session() chan.exec_command(comm) chan.close() except: print 'host', host print traceback.format_exc() self.log(traceback.format_exc()) def sftps(self,host,files): try: lodir = '/opt/onfile' rmdir = '/opt/onfile' client = paramiko.Transport((host,int(self.port))) client.connect(username=self.users,password=self.passwd) sftp = paramiko.SFTPClient.from_transport(client) sftp.put('%s/%s'%(lodir,files),'%s/%s'%(rmdir,files)) client.close() except: print traceback.format_exc() self.log(traceback.format_exc()) def work(self,comm): fp = open('/opt/online/ser_list.txt').readlines() for s in fp: host = s.strip() self.cmds(host,comm) def sftp(self,comm): fp = open('/opt/online/ser_list.txt').readlines() for s in fp: host = s.strip() self.sftps(host,files) if __name__ == '__main__': sc = Remote() func = sys.argv[1] files = sys.argv[2] if func == 'sftp': sc.sftp(files) elif func == 'work': sc.work(files)
Python 之远程复制文件及调用远程命令脚本
原创swq499809608 博主文章分类:Python Shell GO ©著作权
©著作权归作者所有:来自51CTO博客作者swq499809608的原创作品,如需转载,请与作者联系,否则将追究法律责任
![](https://ucenter.51cto.com/images/noavatar_middle.gif)
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
python远程调用stabled diffusion python远程调用centos命令
越来越觉得python的强悍,因为有太多python的第三方库,可以实现太多的功能。本篇就介绍一个第三方库,利用python来操作linux系统中的脚本命令或者直接执行脚本。这个库的名称为paramiko,好像没法言明之意,其github网址为: https://github.com/paramiko/paramikogithub.com Paramiko是用来做什么的呢?主要
centos python centos sftp客户端 c 源码 python paramiko模块下载 python 执行cmd命令 python中!ls -r