python paramiko 的简单使用

Posted on Posted in python
Tips: 本文创建于2016年5月2日,已超过 2 年,内容或图片可能已经失效!

执行远程命令

#!/usr/bin/python  
  
import paramiko  
  
ssh = paramiko.SSHClient()  
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())  
ssh.connect("某IP地址",22,"用户名", "口令")  
stdin, stdout, stderr = ssh.exec_command("你的命令")  
print stdout.readlines()  
ssh.close()  

上传文远程

#!/usr/bin/python  
  
import paramiko  
  
t = paramiko.Transport(("某IP地址",22))  
t.connect(username = "用户名", password = "口令")  
sftp = paramiko.SFTPClient.from_transport(t)  
remotepath='/tmp/test.txt'  
localpath='/tmp/test.txt'  
sftp.put(localpath,remotepath)  
t.close() 

从远程下载文件

#!/usr/bin/python  
  
import paramiko  
  
t = paramiko.Transport(("某IP地址",22))  
t.connect(username = "用户名", password = "口令")  
sftp = paramiko.SFTPClient.from_transport(t)  
remotepath='/tmp/test.txt'  
localpath='/tmp/test.txt'  
sftp.get(remotepath, localpath)  
t.close() 
» 转载请注明来源:呢喃 » python paramiko 的简单使用

Leave a Reply

Your email address will not be published. Required fields are marked *

5 × three =