xref: /btstack/doc/manual/mirror_folder_sftp.sh (revision 7cf4e7c503d012a7e36b7af217511651c6521f0b)
1*7cf4e7c5SMatthias Ringwald#!/bin/bash
2*7cf4e7c5SMatthias RingwaldUSAGE="Usage: mirror_folder_sftp.sh user@host local_path remote_path"
3*7cf4e7c5SMatthias Ringwald
4*7cf4e7c5SMatthias Ringwald# command line checks, bash
5*7cf4e7c5SMatthias Ringwaldif [ $# -ne 3 ]; then
6*7cf4e7c5SMatthias Ringwald        echo ${USAGE}
7*7cf4e7c5SMatthias Ringwald        exit 0
8*7cf4e7c5SMatthias Ringwaldfi
9*7cf4e7c5SMatthias Ringwalduser_host=$1
10*7cf4e7c5SMatthias Ringwaldlocal_path=$2
11*7cf4e7c5SMatthias Ringwaldremote_path=$3
12*7cf4e7c5SMatthias Ringwald
13*7cf4e7c5SMatthias Ringwaldecho Mirroring folder ${local_path} to ${user_host}:${remote_path}
14*7cf4e7c5SMatthias Ringwald
15*7cf4e7c5SMatthias Ringwald# SFTP is very peculiar: recursive put only works for a single directory
16*7cf4e7c5SMatthias Ringwald# note: does not work with sftp of OS X 10.11
17*7cf4e7c5SMatthias Ringwaldfolder=`basename ${remote_path}`
18*7cf4e7c5SMatthias Ringwaldpath=`dirname ${remote_path}`
19*7cf4e7c5SMatthias Ringwaldrm -rf tmp
20*7cf4e7c5SMatthias Ringwaldmkdir tmp
21*7cf4e7c5SMatthias Ringwaldcp -r ${local_path} tmp/${folder}
22*7cf4e7c5SMatthias Ringwaldsftp ${user_host} << EOF
23*7cf4e7c5SMatthias Ringwald  mkdir ${remote_path}
24*7cf4e7c5SMatthias Ringwald  put -r tmp/${folder} ${path}
25*7cf4e7c5SMatthias Ringwald  quit
26*7cf4e7c5SMatthias RingwaldEOF
27*7cf4e7c5SMatthias Ringwaldrm -rf tmp/${folder}
28