paramiko介绍
paramiko功能:实现远程命令执行,文件传输,ssh代理功能
paramiko核心类:SSHClinet 和 SFTPClient
例子:
#!/usr/bin/env/ python
import paramiko
#sshClient 类
#执行远程命令
host='10.207.200.100'
user='root'
password='Netentsec2015'
ssh=paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname=host,password=password,username=user)
stdin,stdout,stderr=ssh.exec_command("ifconfig")
print stdout.read()
ssh.close()
#sftpClient 类
#上传文件到远程
t=paramiko.Transport(host,22)
t.connect(username=user,password=password)
sftp=paramiko.SFTPClient.from_transport(t)
remotepath='/root/license.lic'
localhostpath='d:/license.lic'
sftp.put(localhostpath,remotepath)
t.close()
浙公网安备 33010602011771号