我想通過ssh傳輸大文件,並且可以當前流式傳輸原始文件;如:如何從命令中處理標準輸出,例如「在open()中使用f:」python
with open('somefile','r') as f:
tx.send(filepath='somefile',stream=f.read())
TX是,我有可以流就好了這樣一個更高的水平類的實例,但我希望能夠使用命令,如pv
,dd
和tar
以流爲好。我需要的是:
with run_some_command('tar cfv - somefile') as f:
tx.send(filepath='somefile',stream=f.read())
這將採取stdout作爲流並寫入遠程文件。 我試着做這樣的事情:
p = subprocess.Popen(['tar','cfv','-','somefile'], stdout=subprocess.PIPE)
tx.send(filepath='somefile',stream=p.stdout.readall())
但無濟於事...... 我一直在google搜索試圖找到一個例子一段時間,但至今沒有運氣。 任何幫助將不勝感激!