From 7cf4e7c503d012a7e36b7af217511651c6521f0b Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Thu, 3 Mar 2016 22:10:29 +0100 Subject: [PATCH] docs: scripts to upload folder or file --- doc/manual/mirror_file_sftp.sh | 21 +++++++++++++++++++++ doc/manual/mirror_folder_sftp.sh | 27 +++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100755 doc/manual/mirror_file_sftp.sh create mode 100755 doc/manual/mirror_folder_sftp.sh diff --git a/doc/manual/mirror_file_sftp.sh b/doc/manual/mirror_file_sftp.sh new file mode 100755 index 000000000..105d09c73 --- /dev/null +++ b/doc/manual/mirror_file_sftp.sh @@ -0,0 +1,21 @@ +#!/bin/bash +USAGE="Usage: mirror_file_sftp.sh user@host local_path remote_path" + +# command line checks, bash +if [ $# -ne 3 ]; then + echo ${USAGE} + exit 0 +fi +user_host=$1 +local_path=$2 +remote_path=$3 + +echo Mirroring file ${local_path} to ${user_host}:${remote_path} + +# SFTP is very peculiar: recursive put only works for a single directory +# note: does not work with sftp of OS X 10.11 +sftp ${user_host} << EOF + put ${local_path} ${remote_path} + quit +EOF +rm -rf tmp/${folder} diff --git a/doc/manual/mirror_folder_sftp.sh b/doc/manual/mirror_folder_sftp.sh new file mode 100755 index 000000000..e71970cc2 --- /dev/null +++ b/doc/manual/mirror_folder_sftp.sh @@ -0,0 +1,27 @@ +#!/bin/bash +USAGE="Usage: mirror_folder_sftp.sh user@host local_path remote_path" + +# command line checks, bash +if [ $# -ne 3 ]; then + echo ${USAGE} + exit 0 +fi +user_host=$1 +local_path=$2 +remote_path=$3 + +echo Mirroring folder ${local_path} to ${user_host}:${remote_path} + +# SFTP is very peculiar: recursive put only works for a single directory +# note: does not work with sftp of OS X 10.11 +folder=`basename ${remote_path}` +path=`dirname ${remote_path}` +rm -rf tmp +mkdir tmp +cp -r ${local_path} tmp/${folder} +sftp ${user_host} << EOF + mkdir ${remote_path} + put -r tmp/${folder} ${path} + quit +EOF +rm -rf tmp/${folder}