Skip to content

Instantly share code, notes, and snippets.

@craigvantonder
Created March 18, 2017 16:54
Show Gist options
  • Save craigvantonder/cd5464e16825ed7cc70611323b3d0dca to your computer and use it in GitHub Desktop.
Save craigvantonder/cd5464e16825ed7cc70611323b3d0dca to your computer and use it in GitHub Desktop.
To SCP files from local to remote
#!/bin/bash
# Example: /home/username/Downloads/software.tar.gz
echo -n "Full path of the file to upload: ";
read fileLocation;
# Example: /var/www/mydomain/software.tar.gz
echo -n "Full path of where the file is to be saved: ";
read saveLocation;
# Example: y
echo -n "Do you use an identity file? (y/n): ";
read useidentity;
export useidentity;
if [ $useidentity == "y" ]; then
# Example: /path/to/id_rsa
echo -n "Full path of identity file: ";
read identityLocation;
export identityLocation;
fi
# SCP Params:
# Use port: 22 / define custom port
# Limit Bandwidth to 768kbs (8192kbs x 75 % = 6144kbs)
# Use identity file and define location
# username@host/ip:fileLocation saveLocation
if [ $useidentity == "y" ]; then
scp -P 22 -l 6144 -i $identityLocation $fileLocation $username@$hostname:$saveLocation
else
scp -P 22 -l 6144 $fileLocation $username@$hostname:$saveLocation
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment