SFTP automation example

Example of SFTP command automation.

Following will connect to a server and replace a directory with all it's contents (by removing and re-uploading):

sftp -b /dev/stdin -P 2020 username@host <<EOF
cd some/directory
rmdir target_directory
mkdir target_directory
put -r target_directory
EOF