Automatic Script for SSH Command and SFTP Download In Git Bash

Here’s a script I wrote today to automatically execute a command over SSH using Putty’s PLINK and subsequently download a file using Putty’s PSFTP from a remote Linux host.

My exact use case is using this to execute a remote command that pulls a file from a Docker container to a temp directory. Then I download that file to my local Windows computer.

This pairs well with another blog post I wrote that allows you to automatically set up a public/private key pair and simply copy paste to a notepad located at the below link.

Automate everything – that’s my philosophy.

#Ensure nothing happens outside the directory this script is ran from
cd "$(dirname "$0")"


REMOTE_COMMAND="bash -c 'cd /remoteDirectory/subDirectory/ && sh'"

#Double slash is for git bash path conversion compatibility


PLINK="/c/Program Files/PuTTY/plink.exe"
PSFTP="/c/Program Files/PuTTY/psftp.exe"







One thought on “Automatic Script for SSH Command and SFTP Download In Git Bash

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s