diff options
| author | Adam Olech <nddr89@gmail.com> | 2021-06-24 00:26:13 +0200 |
|---|---|---|
| committer | Adam Olech <nddr89@gmail.com> | 2021-06-24 00:26:13 +0200 |
| commit | 7d50d92d9bb9a63ddafe175ce7a4ec92ba5b6cf1 (patch) | |
| tree | dea17fcd378f0ba52600f60f3dab31fac743b7b7 /tar_over_paramiko.py | |
| parent | fb58f24833919d6e8eb9e2015fa1a96ffbe17af7 (diff) | |
Pipe remote tar output to local tar
Diffstat (limited to 'tar_over_paramiko.py')
| -rwxr-xr-x | tar_over_paramiko.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/tar_over_paramiko.py b/tar_over_paramiko.py index 797a931..0801478 100755 --- a/tar_over_paramiko.py +++ b/tar_over_paramiko.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -import paramiko, sys, os, io, tarfile +import paramiko, sys, os, io, tarfile, subprocess from pathlib import Path if len(sys.argv) != 5: @@ -43,11 +43,20 @@ stdout_type = None stdin.flush() stdin.channel.shutdown_write() +untar = subprocess.Popen( + ["tar", "xf", "-"], + stdin=subprocess.PIPE, + stdout=subprocess.DEVNULL, + ) + tar_data = io.BytesIO() tar_file = open('/tmp/tartest', 'wb') for l in stdout: l_byte = l.encode() + + untar.stdin.write(l_byte) + tar_data.write(l_byte) tar_file.write(l_byte) @@ -61,6 +70,7 @@ for l in stderr: stderr_lines += 1 tar_file.close() +untar.stdin.close() tar_data.seek(0) tar_obj = tarfile.open(fileobj=tar_data, mode='r') |
