forked from Tauop/sshGate-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scpg
executable file
·88 lines (77 loc) · 2.32 KB
/
scpg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/sh
#
# Copyright (c) 2010 Linagora
# Patrick Guiran <[email protected]>
# http://github.com/Tauop/sshGate
#
# sshGate is free software, you can redistribute it and/or modify
# it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
#
# sshGate is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
usage () {
echo "usage:"
echo " send : $0 <file1> ... <file2> <target>:[<rep/file>]"
echo " receive : $0 <target>:[<rep/file>] <file or directory>"
exit 1
}
# check the configuration
sshgate-client-configure
is_target_arg() {
echo "$1" | grep ':' >/dev/null 2>/dev/null
[ $? -eq 0 ] && echo 'true' || echo 'false'
}
if [ $# -lt 2 ]; then
echo "ERROR: bad arguments"
usage
fi
action=
target_host=
target_location=
local_location=
scp_opt=
# get options
while [ true ]; do
case "$1" in
-[1246BCpqrv] ) scp_opt="${scp_opt} $1"; shift;;
-[cFiloPS] ) scp_opt="${scp_opt} $1 '$2'"; shift 2;;
-* ) echo "ERROR: invalid '$1' option"; exit 1;;
* ) break ;;
esac
done
# determine if we want to send or receive files from the target host
if [ "$(is_target_arg "$1")" = "true" ]; then
action='receive'
target_host="${1%%:*}"
target_location="${1##*:}"
shift; # we have parsed the first argument
local_location="$1"
shift;
if [ "$#" -ne 0 ]; then
echo "ERROR: bad arguments"
usage
fi
else
action='send'
# concat files into "${files}", until the last argument
while [ $# -ne 1 ]; do
local_location="${local_location} $1"; shift;
done
if [ "$(is_target_arg "$1")" = "false" ]; then
echo "ERROR: bad arguments"
usage
fi
target_host="${1%%:*}"
target_location="${1##*:}"
fi
[ "${action}" = 'send' ] && eval "scp ${scp_opt} ${local_location} sshgate:${target_host}/${target_location}"
[ "${action}" = 'receive' ] && eval "scp ${scp_opt} sshgate:${target_host}/${target_location} ${local_location}"
exit 0