Paramiko equvalent of pipeline controls and input/output pipes

限于喜欢 提交于 2019-12-09 19:05:07

问题


I need a method of paramiko based file transfer with a lightweight SSH2 server (dropbear) which has no support for SCP or SFTP. Is there a way of achieving a cat and redirect style file transfer, such as:

ssh server "cat remote_file" > local_file

with paramiko channels?

Can paramiko.Transport.open_channel() or Message() do the job? I am unsure of how to proceed.


回答1:


The following may be useful as a starting point (e.g. ./sshpipe host "command"):

#! /usr/bin/env python

import sys
import paramiko

def sshpipe(host, line) :
    client = paramiko.SSHClient()
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    client.connect(host)
    stdin, stdout, stderr = client.exec_command(line)
    output = stdout.read()
    sys.stdout.write(output)
    stdin.close()
    stdout.close()
    stderr.close()
    client.close()

sshpipe(sys.argv[1], sys.argv[2])


来源:https://stackoverflow.com/questions/2133326/paramiko-equvalent-of-pipeline-controls-and-input-output-pipes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!