Python:paramiko模块
来源:互联网 发布:黄子韬微博故事软件 编辑:程序博客网 时间:2024/05/18 03:48
#!/usr/bin/env python #coding=utf-8import os import paramiko import datetime #远程服务器 hostname = '192.168.1.xxx' port = xxxusername = 'fangyali'password = 'xxx' local_dir='/home/fangyali/test' remote_dir='/tmp/fangyali' def ssh(): try: s = paramiko.SSHClient() #读取know_host #s.load_system_host_keys() s.set_missing_host_key_policy(paramiko.AutoAddPolicy()) #建立SSH连接 s.connect(hostname,port,username,password) stdin,stdout,stderr = s.exec_command('/sbin/ifconfig;free;df -h') #打印标准输出 print stdout.read() except Exception,e: print "error!",e finally: s.close() def upload(): try: t=paramiko.Transport((hostname,port)) t.connect(username=username,password=password) sftp=paramiko.SFTPClient.from_transport(t) #本地使用os模块,远端使用sftp.listdir(remote_dir) files=os.listdir(local_dir) for f in files: print '' print '#########################################' print 'Beginning to upload file %s ' % datetime.datetime.now() print 'Uploading file:',os.path.join(local_dir,f) #上传put:local-remote,下载get:remote-local sftp.put(os.path.join(local_dir,f),os.path.join(remote_dir,f)) print 'Upload file success %s ' % datetime.datetime.now() print '' print '##########################################' except Exception,e: print "error!",e finally: t.close() def download(): try: t=paramiko.Transport((hostname,port)) t.connect(username=username,password=password) sftp=paramiko.SFTPClient.from_transport(t) #本地使用os模块,远端使用sftp.listdir(remote_dir) files=sftp.listdir(remote_dir) for f in files: print '' print '#########################################' print 'Beginning to download file from %s %s ' % (hostname,datetime.datetime.now()) print 'Downloading file:',os.path.join(remote_dir,f) sftp.get(os.path.join(remote_dir,f),os.path.join(local_dir,f)) #上传put:local-remote,下载get:remote-local print 'Download file success %s ' % datetime.datetime.now() print '' print '##########################################' except Exception,e: print "error!",e finally: t.close() def download_one(): try: t=paramiko.Transport((hostname,port)) t.connect(username=username,password=password) sftp=paramiko.SFTPClient.from_transport(t) sftp.get("/tmp/fangyali/mysql_status.txt3306","/home/fangyali/test/1.txt") except Exception,e: print "error!",e finally: t.close() ssh()upload()download()
0 0
- python ssh模块paramiko
- python安装paramiko模块
- Python paramiko模块安装
- Python模块paramiko安装
- Python Paramiko模块【转载】
- python模块之 paramiko
- Python:paramiko模块
- python安装paramiko模块
- [Python] 安装Paramiko模块
- Python--paramiko模块
- python --- paramiko模块
- python paramiko模块简介
- python中的paramiko模块
- python之paramiko模块
- Python 模块paramiko简单使用方法
- python模块paramiko与ssh
- Learning Python(11)--paramiko模块
- python 3.3 安装paramiko模块
- 单例模式
- 实用的添加购物车抛物线动画和自由落体类型动画
- 黑马程序员——集合框架的工具类
- java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
- UVa 10791 Minimum Sum LCM
- Python:paramiko模块
- javac带package和不带package的运行方式
- SCU2016-02 Q题区间dp入门
- java中int,char,string三种类型的相互转换
- 关于syslog报文的RFC规范
- HTTP Live Streaming直播(iOS直播)技术分析与实现
- 【转载】微信公众帐号开发教程第3篇-开发模式启用及接口配置
- Cannot read property 'nodeType' of undefined
- android中的后退键——onBackPressed()的使用