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