#!/usr/bin/env bash if [ "$#" -ne 3 ]; then echo "usage: $0 " exit 1 fi printf -v remote_dir %q $3 cd $1 tar cf - . | ssh $2 "set -xe TEMP_DIR=\$(mktemp -d) cd \$TEMP_DIR tar xvf - rm -rf $remote_dir mv \$TEMP_DIR $remote_dir "