Python是否将SSH会话的输出保存到CSV?

2024-10-03 17:15:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在测试一个供应商提供的服务,你可以在那里新鲜好了,好了没有API,但您必须通过ssh登录才能获得在ssh窗口中每秒更新的数据。 如何将数据保存到计算机上的本地文件中? 我试过这个-

import base64
import paramiko

client = paramiko.SSHClient()

client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect('rt01.rtfxd.com',port="6174", username='rt01.demo', password='rtfxd')
stdin, stdout, stderr = client.exec_command('cat /proc/meminfo')
for line in stdout:
    print('... ' + line.strip('\n'))
client.close()

但它并没有给我任何输出。饲料来自网址:www.rtfxd.com登录是为了演示。 任何解决方法都将不胜感激。你知道吗


Tags: 文件数据importcomclientapiparamiko计算机
1条回答
网友
1楼 · 发布于 2024-10-03 17:15:39

stdin, stdout, stderr是类似文件的对象,请尝试:

while True:
    print(stdout.read().decode(), end='')
    if stdout.channel.exit_status_ready():
        break

相关问题 更多 >