dotfiles/bin/scp_turbo

37 lines
906 B
Bash
Executable file

#!/usr/bin/env bash
print_help() {
cat <<HELP
$(basename "$0"): A fast transfer for single files
- Supports input pipes! (useful for gpg pipes)
- 2x faster than scp, right around rsync speeds
- Shows a progress bar!
Examples:
$ scp_turbo orca dotfiles.tgz.gpg /dev/shm/dotfiles.tgz.gpg
$ cat dotfiles.tgz.gpg | scp_turbo orca /dev/shm/dotfiles.tgz.gpg
$ tar cz kattis | gpg -e -r emiliko@mami2.moe | scp_turbo orca /dev/shm/kattis.tgz.gpg
HELP
}
if [[ "$1" == --help || "$1" == -h ]]; then
print_help
exit 1
elif [[ $# -eq 2 ]]; then
declare -r remote="$1"
declare -r to="$2"
pv | ssh -o ClearAllForwardings=yes "$remote" "cat > '$to'"
elif [[ $# -eq 3 ]]; then
declare -r remote="$1"
declare -r from="$2"
declare -r to="$3"
cat "$from" \
| pv -s $(stat -c %s "$from") \
| ssh -o ClearAllForwardings=yes "$remote" "cat > '$to'"
else
print_help
exit 2
fi