Apr 3, 2018

Copy by pipe to ssh

ssh remote1 "cd srcdir; tar cf - dir |
ssh remote2 "cd destdir | tar xvf -"

With compression

compress=gzip
decompress=gunzip

ssh remote1 "cd srcdir; tar cf - dir | $compress" |
ssh remote2 "cd destdir; $decompress | tar xvf -"
Note that the compression/decompression is configurable without depending on the version of tar.

With checksum verification into the pipe:

compress=gzip
decompress=gunzip

ckprg=md5sum
cksum=/tmp/cksum

ssh remote1 "cd srcdir; tar cf - dir | $compress | tee <($ckprg > $cksum)" |
ssh remote2 "cd destdir; tee <($ckprg > $cksum) | $decompress | tar xvf -"

ssh remote1 cat $cksum
ssh remote2 cat $cksum