注意:对诸如Pramiko之类的任何模块都不感兴趣

我正在尝试在不创建本地文件的情况下在远程服务器上保存一些二进制数据。

作为一项测试,我从文件中读取内容,但后来我将其替换为数据文件:

ps = subprocess.Popen(['cat', "/delta/ftp/GSM.PRICINT_TBL.dmp"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)

下一步,我想将数据SSH到远程服务器
ssh = subprocess.Popen(["ssh", '-XC', '-c', 'blowfish-cbc,arcfour', 'deltadmin@archiveserver', 'echo - >/tmp/test.log'],
                                shell=False,
                                stdin = ps.stdout,
                                stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE)
        result = ssh.stdout.readlines()
        if result == []:
            error = ssh.stderr.readlines()
            print >>sys.stderr, "ERROR: %s" % error
        else:
            print result

我使用“-”,因此cat可以接受标准输入。
预期结果是/tmp/test.log中的数据,但我只能看到



任何想法如何使其工作?

最佳答案

我想通了:

echo 'test'|ssh -XC -c blowfish-cbc,arcfour bicadmin@nitarchive -T 'gzip - >/tmp/test.gz'

然后在远程服务器上:
 zcat /tmp/test.gz
test

对于cat,我们在重定向后需要空格:
cat - > /tmp/test.txt

关于python-2.7 - 有没有一种方法可以使用ssh和Python将二进制流传输到远程服务器?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44528086/

10-13 04:55