#!/usr/bin/env python
#-*- encoding -*-
import paramiko
transport = paramiko.Transport(('192.168.11.181', 22))
transport.connect(username='ahwater', password='Aa7788..')
ssh = paramiko.SSHClient()
ssh._transport = transport
stdin, stdout, stderr = ssh.exec_command('netstat -na')
print stdout.read()
stdin, stdout, stderr = ssh.exec_command('hostname')
print stdout.read()
transport.close()
下载远程文件
#!/usr/bin/env python
#-*- encoding:utf-8 -*-
import paramiko
transport = paramiko.Transport(('192.168.11.181',22))
transport.connect(username='ahwater',password='Aa7788..')
#创建sftp对象
sftp = paramiko.SFTPClient.from_transport(transport)
# 将location.py 上传至服务器 /tmp/test.py
#sftp.put('/tmp/location.py', '/tmp/test.py')
# 将remove_path 下载到本地 local_path
sftp.get(r'C:\\mo\\res.txt', r'c:\\res.txt')
transport.close()