Skip to content

Instantly share code, notes, and snippets.

@marxspawn
Last active September 22, 2023 04:06
Show Gist options
  • Save marxspawn/c0926899cdb1a9b51a3951f7b3385e2f to your computer and use it in GitHub Desktop.
Save marxspawn/c0926899cdb1a9b51a3951f7b3385e2f to your computer and use it in GitHub Desktop.
SCP SSH Bash script to place to/from files in correct folder
#!/bin/bash
######################################################################
##### SSH Bash Script to send/recieve files #####
##### Created By: Raymond Anderson #####
######################################################################
clear
echo "
------------------------------------
- Choose Option Number from Menu:
1. Send File SSH
2. Get File SSH
3. Exit
------------------------------------
"
read -p "Choose Option 1, 2, or 3 ---> "
if [[ $REPLY =~ ^[1-3]$ ]]; then
if [[ $REPLY == 1 ]]; then
clear ; echo '' ; echo " - Enter the location of the file/to/send: "
echo '' ; read "fileFromLocation"
echo '' ; echo " - Enter the location of where to/send/file: "
echo '' ; read "fileToLocation"
echo '' ; echo " - Enter the name of host pc: "
echo '' ; read "hostName"
echo '' ; echo " - Enter the address to host pc: "
echo '' ; read "hostPC"
echo '' ; echo "scp $fileFromLocation $hostName@$hostPC:$fileToLocation"
echo '' ; scp $fileFromLocation $hostName@$hostPC:$fileToLocation
sleep 2
exit
fi
if [[ $REPLY == 2 ]]; then
clear ; echo '' ; echo " - Enter the location of the file/to/get: "
echo '' ; read "fileFromLocation"
echo '' ; echo " - Enter the location of where to/put/file: "
echo '' ; read "fileToLocation"
echo '' ; echo " - Enter the name of host pc where the file is located: "
echo '' ; read "hostName"
echo '' ; echo " - Enter the address to host pc: "
echo '' ; read "hostPC"
echo '' ; echo "scp $hostName@$hostPC:$fileFromLocation $fileToLocation"
echo '' ; scp $hostName@$hostPC:$fileFromLocation $fileToLocation
sleep 2
exit
fi
if [[ $REPLY == 3 ]]; then
clear ; echo " - PC $HOSTNAME Will now exit... "
uptime ; sleep 2
exit
fi
else
echo " - Option not available" ; sleep 1
echo " - 1 - 2 - 3 -"
exit
fi
exit
@marxspawn
Copy link
Author

marxspawn commented Aug 14, 2018

SSH Bash script to aid with sending and receiving files from Mac OS X Terminal on local network using SCP command

I don't use ssh send/receive too often. But when I do I end up searching google each time for a refresher course.
So I made this to help me with that process along with learning to string code together.


  • The script process will ask a few simple questions

    • If you are sending to or getting from the Remote Host
    • File location and destination
    • The Remote Host Name
    • The Remote Host IP Address
  • Finally it will place the information provided in the correct order for the scp command and initialize the process
  • leaving you with the process running from terminal
  • Any passwords needed can be applied after the script exits

  alias sshFile='/path/to/this.bashScript'                # Add an alias to initiate the script process quicker 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment