Bart Simons

Bart Simons


Thoughts, stories and ideas.

Bart Simons
Author

Share


Tags


.net .net core Apache C# CentOS LAMP NET Framework Pretty URLs Windows Server WireGuard WireGuard.io access log add analysis android api at the same time authentication authorization automate automation azure azurerm backup bash basics batch bootstrap build capture cheat sheet chromium chroot class cli click to close code snippet command line commands compile compiling compression containers control controller controlling convert cpu usage create credentials csv csvparser curl data dd deployment desktop detect devices disable diskpart dism distributed diy docker dom changes dotnet core drivers ease of access encryption example export file transfer files fix folders generalize getting started ghost ghost.org gui guide gunicorn gzip html html tables icewarp igd imagex import inotify install installation interactive ios iphone itunes java javascript jquery json kiosk kotlin linux live load data loading screen lock screen loopback audio lxc lxd lxml macos manage manually message messages minio mirrored mod_rewrite monitor monitoring mutationobserver mysql nexmo nginx no oobe node node.js nodejs not installing notification notifications object storage on desktop one command openssl owncloud parallels parallels tools parse perfect philips hue play port forwarding portainer.io powershell processing ps-spotify python quick raspberry pi record rip ripping rsync rtmp save save data sbapplication scraping script scripting scriptingbridge scripts security send server service sharedpreferences sms songs sonos spotify spotify api spotlight ssh stack streaming streamlink studio sudo swarm swift sync sysprep system audio systemd tables terminal tracking tutorial twilio ubiquiti ubuntu ubuntu 18.04 ui code unifi unlock unsplash source upnp uptime usb tethering wallpapers wasapi website websites webview windows windows 10 without itunes without oobe workaround xaml

Quickest way to transfer files from your terminal

Do you often use the SCP command to transfer files from your computer to a remote server? This little code snippet may come to good use for you:

function push {
	if [[ $1 == "config" ]]; then
		if [[ $# == 1 ]]; then
			echo "Usage:   push config username hostname destinationpath optionalkeyfile"
			echo "Example: push config root 1.2.3.4 /root/ ~/Documents/SSHKeys/server.key"
		elif [[ $# == 2 ]] || [[ $# == 3 ]]; then
			echo "Too few arguments were specified, run 'push config' for help."
		elif [[ $# == 4 ]]; then
			PUSH_ISCONFIGURED=1
			PUSH_USERNAME=$2
			PUSH_HOST=$3
			PUSH_DESTINATION=$4
		elif [[ $# == 5 ]]; then
			PUSH_ISCONFIGURED=1
			PUSH_USERNAME=$2
			PUSH_HOST=$3
			PUSH_DESTINATION=$4
			PUSH_KEYFILE=$5
		fi
	elif [[ $# == 0 ]]; then
		if [[ $PUSH_ISCONFIGURED == 1 ]] && [[ ! -z $PUSH_KEYFILE ]]; then
			scp -ri $PUSH_KEYFILE . $PUSH_USERNAME@$PUSH_HOST:$PUSH_DESTINATION
		elif [[ $PUSH_ISCONFIGURED == 1 ]] && [[ -z $PUSH_KEYFILE ]]; then
			scp -r . $PUSH_USERNAME@$PUSH_HOST:$PUSH_DESTINATION
		elif [[ -z $PUSH_ISCONFIGURED ]]; then
			echo "Usage:   push config username hostname destinationpath optionalkeyfile"
			echo "Example: push config root 1.2.3.4 /root/ ~/Documents/SSHKeys/server.key"
		fi
	fi
}

All I have to do now to upload files is using push config to setup connection parameters, and push in my code directory to quickly push files.

A nice little time-saving code snippet if you use the scp command often.

You can put it in your ~/.zshrc file if you use ZSH, or in ~/.bashrc if you use Bash as your shell.

Bart Simons
Author

Bart Simons

View Comments