1#!/bin/bash 2USAGE="Usage: mirror_folder_sftp.sh user@host local_path remote_path" 3 4# command line checks, bash 5if [ $# -ne 3 ]; then 6 echo ${USAGE} 7 exit 0 8fi 9user_host=$1 10local_path=$2 11remote_path=$3 12 13echo Mirroring folder ${local_path} to ${user_host}:${remote_path} 14 15# SFTP is very peculiar: recursive put only works for a single directory 16# note: does not work with sftp of OS X 10.11 17folder=`basename ${remote_path}` 18path=`dirname ${remote_path}` 19rm -rf tmp 20mkdir tmp 21cp -r ${local_path} tmp/${folder} 22sftp ${user_host} << EOF 23 mkdir ${remote_path} 24 put -r tmp/${folder} ${path} 25 quit 26EOF 27rm -rf tmp/${folder} 28