-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscp-with-password.sh
executable file
·52 lines (46 loc) · 1.21 KB
/
scp-with-password.sh
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
#!/usr/bin/env bash
# -*- coding: UTF-8 -*-
## SSH connection with password
## options
## -u, --user <string> username [default: carlolo]
## -a, --address <ip>
## -s, --source <path>
## -d, --destination <path>
# GENERATED_CODE: start
# Default values
_user=carlolo
# No-arguments is not allowed
[ $# -eq 0 ] && sed -ne 's/^## \(.*\)/\1/p' $0 && exit 1
# Converting long-options into short ones
for arg in "$@"; do
shift
case "$arg" in
"--user") set -- "$@" "-u";;
"--address") set -- "$@" "-a";;
"--source") set -- "$@" "-s";;
"--destination") set -- "$@" "-d";;
*) set -- "$@" "$arg"
esac
done
function print_illegal() {
echo Unexpected flag in command line \"$@\"
}
# Parsing flags and arguments
while getopts 'hu:a:s:d:' OPT; do
case $OPT in
h) sed -ne 's/^## \(.*\)/\1/p' $0
exit 1 ;;
u) _user=$OPTARG ;;
a) _address=$OPTARG ;;
s) _source=$OPTARG ;;
d) _destination=$OPTARG ;;
\?) print_illegal $@ >&2;
echo "---"
sed -ne 's/^## \(.*\)/\1/p' $0
exit 1
;;
esac
done
# GENERATED_CODE: end
set -x
scp -o PreferredAuthentications=password -o PubkeyAuthentication=no "$_source" $_user@$_address:"$_destination"