Scripts: add scp_turbo script

This commit is contained in:
Akemi Izuko 2024-05-19 13:36:17 -06:00
parent a32f42d404
commit 388b275bd0
Signed by: akemi
GPG key ID: 8DE0764E1809E9FC

36
bin/scp_turbo Executable file
View file

@ -0,0 +1,36 @@
#!/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