-
Notifications
You must be signed in to change notification settings - Fork 3
/
upload_sftp
executable file
·52 lines (44 loc) · 1.43 KB
/
upload_sftp
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
#!/bin/bash
configfile=server.conf
usage() { echo "Usage: $0 [-c <configfile>] directories [...] " 1>&2; exit $1; }
while getopts "c:h" o; do
case "${o}" in
c) configfile=${OPTARG}
if [[ ! -r ${configfile} ]]; then
echo "Cannot read ${configfile}" 1>&2
usage 2
fi
;;
h) usage 0 ;;
*) usage 2 ;;
esac
done
shift $((OPTIND-1))
. ${configfile}
: ${fileserver:?}
# ${srvport}
: ${expname:?}
: ${basedir:=$(pwd)}
: ${download:?}
: ${parallel:=16}
: ${contimeout:=300}
: ${retries:=10}
: ${iotimeout:=300}
if [[ $( < ~/.netrc ) =~ machine[[:space:]]+${fileserver}[[:space:]]?login[[:space:]]+([^[:space:]]+) ]]; then
username="${BASH_REMATCH[1]}"
elif [[ $( < ~/.ssh/config ) =~ Host[[:space:]]+${fileserver}[[:space:]]+ ]]; then
username=
else
echo "cannot find login for machine ${fileserver} in ~/.netrc nor ~/.ssh/config" >&2
exit 1
fi
if (( ${#@} )); then
dir=( "${@/#/ --directory=${download}/}" )
source="${dir[*]}"
else
source="--directory=${download}/*"
echo "directories to upload are currently mandatory !" >&2
exit 2
fi
cd ${basedir}
exec lftp -c "set cmd:move-background false; set net:timeout $(( contimeout / retries)); set net:max-retries ${retries}; set net:reconnect-interval-base 8; set xfer:timeout ${iotimeout}; connect sftp://${username:+${username}@}${fileserver}${srvport:+:${srvport}}; mirror --reverse --continue --no-perms --no-umask --parallel=${parallel} --loop --target-directory=${expname} ${source}"