Last active
January 12, 2023 22:44
-
-
Save stonecharioteer/c3de324215fcc0dd5baddef5c2d555f6 to your computer and use it in GitHub Desktop.
File to help rsync over ngrok.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Make sure to use this on the server side: `ngrok tcp 22` | |
# Usage: | |
# rsync_ngrok USERNAME REMOTEDIRPATH PORTNUMBER LOCALDIRPATH | |
# if no arguments are given to the script. | |
if [[ $# -eq 0 ]] ; then | |
echo 'rsync_ngrok Script used to download files or folders from remote host offering usage via ngrok.' | |
echo 'Usage: rsync_ngrok USERNAME REMOTEDIRPATH PORTNUMBER LOCALDIRPATH' | |
echo "" | |
exit 0 | |
fi | |
# Capture the arguments | |
USERNAME=$1 | |
REMOTEDIRPATH=$2 | |
PORTNUMBER=${3:-22} # default port 22. It's highly unlikely ngrok will ever give us that port though. | |
LOCALDIRPATH=${4:-.} # Default directory is the current directory. Files will be copied here. | |
download() { | |
# Function to attempt download. | |
echo 'Attemping download!' | |
rsync -avzP -e "ssh -p $PORTNUMBER" [email protected]:$REMOTEDIRPATH $LOCALDIRPATH | |
} | |
echo "Beginning download of $REMOTEDIRPATH from [email protected]:$PORTNUMBER to $LOCALDIRPATH" | |
download | |
while [ $? -ne 0 ]; do # Keep repeating for as long as the exit code for the previously executed line is not 0. | |
echo 'Retrying....' | |
sleep 5 | |
download | |
done | |
echo 'Done!' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment