我需要一种基于paramiko的文件传输方法,它使用轻量级SSH2服务器(dropbear),不支持SCP或SFTP。有没有办法实现cat和重定向样式文件传输,例如:
ssh server "cat remote_file" > local_file
有paramiko个频道?
paramiko.Transport.open_channel()或Message()可以完成这项工作吗?我不确定如何继续。
答案 0 :(得分:3)
以下内容可能有用作起点(例如./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])