paramiko分开执行多条命令 不像之前一样使用\n


#!/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()


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM