You open a new SSH process for Machine2 using subprocess.Popen , and then write your data to STDIN.
import subprocess cmd = ['ssh', 'user@machine2', 'mkdir -p output/dir; cat - > output/dir/file.dat'] p = subprocess.Popen(cmd, stdin=subprocess.PIPE) your_inmem_data = 'foobarbaz\0' * 1024 * 1024 for chunk_ix in range(0, len(your_inmem_data), 1024): chunk = your_inmem_data[chunk_ix:chunk_ix + 1024] p.stdin.write(chunk)
I just checked that it works as advertised, and copies all empty bytes 10485760.
PS . A potentially cleaner or more elegant solution would be for the Python program to write its output to sys.stdout instead and make the ssh pipe from the outside:
$ python process.py | ssh <the same ssh command>
Erik allik
source share