• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#	$OpenBSD: sftp-cmds.sh,v 1.11 2010/12/04 00:21:19 djm Exp $
2#	Placed in the Public Domain.
3
4# XXX - TODO:
5# - chmod / chown / chgrp
6# - -p flag for get & put
7
8tid="sftp commands"
9
10DATA=/bin/ls${EXEEXT}
11COPY=${OBJ}/copy
12# test that these files are readable!
13for i in `(cd /bin;echo l*)`
14do
15	if [ -r $i ]; then
16		GLOBFILES="$GLOBFILES $i"
17	fi
18done
19
20if have_prog uname
21then
22	case `uname` in
23	CYGWIN*)
24		os=cygwin
25		;;
26	*)
27		os=`uname`
28		;;
29	esac
30else
31	os="unknown"
32fi
33
34# Path with embedded quote
35QUOTECOPY=${COPY}".\"blah\""
36QUOTECOPY_ARG=${COPY}'.\"blah\"'
37# File with spaces
38SPACECOPY="${COPY} this has spaces.txt"
39SPACECOPY_ARG="${COPY}\ this\ has\ spaces.txt"
40# File with glob metacharacters
41GLOBMETACOPY="${COPY} [metachar].txt"
42
43rm -rf ${COPY} ${COPY}.1 ${COPY}.2 ${COPY}.dd ${COPY}.dd2 ${BATCH}.*
44mkdir ${COPY}.dd
45
46verbose "$tid: lls"
47(echo "lcd ${OBJ}" ; echo "lls") | ${SFTP} -D ${SFTPSERVER} 2>&1 | \
48	grep copy.dd >/dev/null 2>&1 || fail "lls failed"
49
50verbose "$tid: lls w/path"
51echo "lls ${OBJ}" | ${SFTP} -D ${SFTPSERVER} 2>&1 | \
52	grep copy.dd >/dev/null 2>&1 || fail "lls w/path failed"
53
54verbose "$tid: ls"
55echo "ls ${OBJ}" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
56	|| fail "ls failed"
57# XXX always successful
58
59verbose "$tid: shell"
60echo "!echo hi there" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
61	|| fail "shell failed"
62# XXX always successful
63
64verbose "$tid: pwd"
65echo "pwd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
66	|| fail "pwd failed"
67# XXX always successful
68
69verbose "$tid: lpwd"
70echo "lpwd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
71	|| fail "lpwd failed"
72# XXX always successful
73
74verbose "$tid: quit"
75echo "quit" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
76	|| fail "quit failed"
77# XXX always successful
78
79verbose "$tid: help"
80echo "help" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
81	|| fail "help failed"
82# XXX always successful
83
84rm -f ${COPY}
85verbose "$tid: get"
86echo "get $DATA $COPY" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
87	|| fail "get failed"
88cmp $DATA ${COPY} || fail "corrupted copy after get"
89
90rm -f ${COPY}
91verbose "$tid: get quoted"
92echo "get \"$DATA\" $COPY" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
93	|| fail "get failed"
94cmp $DATA ${COPY} || fail "corrupted copy after get"
95
96if [ "$os" != "cygwin" ]; then
97rm -f ${QUOTECOPY}
98cp $DATA ${QUOTECOPY}
99verbose "$tid: get filename with quotes"
100echo "get \"$QUOTECOPY_ARG\" ${COPY}" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
101	|| fail "get failed"
102cmp ${COPY} ${QUOTECOPY} || fail "corrupted copy after get with quotes"
103rm -f ${QUOTECOPY} ${COPY}
104fi
105
106rm -f "$SPACECOPY" ${COPY}
107cp $DATA "$SPACECOPY"
108verbose "$tid: get filename with spaces"
109echo "get ${SPACECOPY_ARG} ${COPY}" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
110        || fail "get failed"
111cmp ${COPY} "$SPACECOPY" || fail "corrupted copy after get with spaces"
112
113rm -f "$GLOBMETACOPY" ${COPY}
114cp $DATA "$GLOBMETACOPY"
115verbose "$tid: get filename with glob metacharacters"
116echo "get \"${GLOBMETACOPY}\" ${COPY}" | \
117	${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 || fail "get failed"
118cmp ${COPY} "$GLOBMETACOPY" || \
119	fail "corrupted copy after get with glob metacharacters"
120
121rm -f ${COPY}.dd/*
122verbose "$tid: get to directory"
123echo "get $DATA ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
124        || fail "get failed"
125cmp $DATA ${COPY}.dd/`basename $DATA` || fail "corrupted copy after get"
126
127rm -f ${COPY}.dd/*
128verbose "$tid: glob get to directory"
129echo "get /bin/l* ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
130        || fail "get failed"
131for x in $GLOBFILES; do
132        cmp /bin/$x ${COPY}.dd/$x || fail "corrupted copy after get"
133done
134
135rm -f ${COPY}.dd/*
136verbose "$tid: get to local dir"
137(echo "lcd ${COPY}.dd"; echo "get $DATA" ) | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
138        || fail "get failed"
139cmp $DATA ${COPY}.dd/`basename $DATA` || fail "corrupted copy after get"
140
141rm -f ${COPY}.dd/*
142verbose "$tid: glob get to local dir"
143(echo "lcd ${COPY}.dd"; echo "get /bin/l*") | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
144        || fail "get failed"
145for x in $GLOBFILES; do
146        cmp /bin/$x ${COPY}.dd/$x || fail "corrupted copy after get"
147done
148
149rm -f ${COPY}
150verbose "$tid: put"
151echo "put $DATA $COPY" | \
152	${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 || fail "put failed"
153cmp $DATA ${COPY} || fail "corrupted copy after put"
154
155if [ "$os" != "cygwin" ]; then
156rm -f ${QUOTECOPY}
157verbose "$tid: put filename with quotes"
158echo "put $DATA \"$QUOTECOPY_ARG\"" | \
159	${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 || fail "put failed"
160cmp $DATA ${QUOTECOPY} || fail "corrupted copy after put with quotes"
161fi
162
163rm -f "$SPACECOPY"
164verbose "$tid: put filename with spaces"
165echo "put $DATA ${SPACECOPY_ARG}" | \
166	${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 || fail "put failed"
167cmp $DATA "$SPACECOPY" || fail "corrupted copy after put with spaces"
168
169rm -f ${COPY}.dd/*
170verbose "$tid: put to directory"
171echo "put $DATA ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
172	|| fail "put failed"
173cmp $DATA ${COPY}.dd/`basename $DATA` || fail "corrupted copy after put"
174
175rm -f ${COPY}.dd/*
176verbose "$tid: glob put to directory"
177echo "put /bin/l? ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
178	|| fail "put failed"
179for x in $GLOBFILES; do
180	cmp /bin/$x ${COPY}.dd/$x || fail "corrupted copy after put"
181done
182
183rm -f ${COPY}.dd/*
184verbose "$tid: put to local dir"
185(echo "cd ${COPY}.dd"; echo "put $DATA") | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
186	|| fail "put failed"
187cmp $DATA ${COPY}.dd/`basename $DATA` || fail "corrupted copy after put"
188
189rm -f ${COPY}.dd/*
190verbose "$tid: glob put to local dir"
191(echo "cd ${COPY}.dd"; echo "put /bin/l?") | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
192	|| fail "put failed"
193for x in $GLOBFILES; do
194        cmp /bin/$x ${COPY}.dd/$x || fail "corrupted copy after put"
195done
196
197verbose "$tid: rename"
198echo "rename $COPY ${COPY}.1" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
199	|| fail "rename failed"
200test -f ${COPY}.1 || fail "missing file after rename"
201cmp $DATA ${COPY}.1 >/dev/null 2>&1 || fail "corrupted copy after rename"
202
203verbose "$tid: rename directory"
204echo "rename ${COPY}.dd ${COPY}.dd2" | \
205	${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 || \
206	fail "rename directory failed"
207test -d ${COPY}.dd && fail "oldname exists after rename directory"
208test -d ${COPY}.dd2 || fail "missing newname after rename directory"
209
210verbose "$tid: ln"
211echo "ln ${COPY}.1 ${COPY}.2" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 || fail "ln failed"
212test -f ${COPY}.2 || fail "missing file after ln"
213cmp ${COPY}.1 ${COPY}.2 || fail "created file is not equal after ln"
214
215verbose "$tid: ln -s"
216rm -f ${COPY}.2
217echo "ln -s ${COPY}.1 ${COPY}.2" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 || fail "ln -s failed"
218test -h ${COPY}.2 || fail "missing file after ln -s"
219
220verbose "$tid: mkdir"
221echo "mkdir ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
222	|| fail "mkdir failed"
223test -d ${COPY}.dd || fail "missing directory after mkdir"
224
225# XXX do more here
226verbose "$tid: chdir"
227echo "chdir ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
228	|| fail "chdir failed"
229
230verbose "$tid: rmdir"
231echo "rmdir ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
232	|| fail "rmdir failed"
233test -d ${COPY}.1 && fail "present directory after rmdir"
234
235verbose "$tid: lmkdir"
236echo "lmkdir ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
237	|| fail "lmkdir failed"
238test -d ${COPY}.dd || fail "missing directory after lmkdir"
239
240# XXX do more here
241verbose "$tid: lchdir"
242echo "lchdir ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
243	|| fail "lchdir failed"
244
245rm -rf ${COPY} ${COPY}.1 ${COPY}.2 ${COPY}.dd ${COPY}.dd2 ${BATCH}.*
246rm -rf ${QUOTECOPY} "$SPACECOPY" "$GLOBMETACOPY"
247
248
249