File: myftpput

package info (click to toggle)
foo2zjs 20171202dfsg0-2
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 9,320 kB
  • sloc: ansic: 40,789; xml: 12,512; sh: 7,385; makefile: 1,705; objc: 573; tcl: 173; perl: 102; python: 8
file content (107 lines) | stat: -rwxr-xr-x 1,615 bytes parent folder | download
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/sh

#
# only the file in ~/geo/myftpput is writeable!
#

PROGNAME="$0"

usage() {
	cat <<EOF
NAME
    `basename $PROGNAME` - Ncftp/lftp put with -f option

SYNOPSIS
    `basename $PROGNAME` -f login.cfg dir files

DESCRIPTION
    Put files on to the web. Uses ncftp style configuration file.

OPTIONS
    -S		Use lftp and sftp://user@host
    -m		mkdir the directory
    -f XX	Read the file XX for host, user, and password information:
		host <hostname>
		user <username>
		pass <password>
    -D lvl	Debug level

EXAMPLE
    Using ncftp:

	myftpput -f ~/.ncftp-website geo wherigo2jpg wherigo2lua

    Using lftp:

	myftpput -S -f ~/.ncftp-website geo wherigo2jpg wherigo2lua

EOF

	exit 1
}

#
#       Report an error and exit
#
error() {
	echo "`basename $PROGNAME`: $1" >&2
	exit 1
}

debug() {
	if [ $DEBUG -ge $1 ]; then
	    echo "`basename $PROGNAME`: $2" >&2
	fi
}

#
#       Process the options
#
DEBUG=0
SFTP=0
CFG=
FTP=
while getopts "mSf:D:h?" opt
do
	case $opt in
	S)	SFTP=1;;
	f)	CFG="$OPTARG";;
	m)	FTP="-m $FTP";;
	D)	DEBUG="$OPTARG";;
	h|\?)	usage;;
	esac
done
shift `expr $OPTIND - 1`

#
#	Main Program
#
if [ -r "$CFG" ]; then
    host=$(grep host "$CFG" | tail -1 | awk '{print $2}')
    user=$(grep user "$CFG" | tail -1 | awk '{print $2}')
    pass=$(grep pass "$CFG" | tail -1 | awk '{print $2}')
else
    usage
fi

DIR="$1"; shift

if [ "$SFTP" = 0 ]; then
    ncftp <<-EOF
	open -u $user -p $pass $host
	mkdir $DIR
	cd $DIR
	mput -f $*
	quit
	EOF
else
    lftp <<-EOF
	set sftp:auto-confirm yes
	open sftp://$host
	user $user $pass
	mkdir -f -p $DIR
	cd $DIR
	mput $*
	quit
	EOF
fi