xref: /freebsd/crypto/openssh/regress/sftp-cmds.sh (revision 031beb4e239bfce798af17f5fe8dba8bcaf13d99)
1#	$OpenBSD: sftp-cmds.sh,v 1.15 2022/03/31 03:07:33 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
80rm -f ${QUOTECOPY}
81cp $DATA ${QUOTECOPY}
82verbose "$tid: get filename with quotes"
83echo "get \"$QUOTECOPY_ARG\" ${COPY}" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
84	|| fail "get failed"
85cmp ${COPY} ${QUOTECOPY} || fail "corrupted copy after get with quotes"
86rm -f ${QUOTECOPY} ${COPY}
87
88rm -f "$SPACECOPY" ${COPY}
89cp $DATA "$SPACECOPY"
90verbose "$tid: get filename with spaces"
91echo "get ${SPACECOPY_ARG} ${COPY}" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
92        || fail "get failed"
93cmp ${COPY} "$SPACECOPY" || fail "corrupted copy after get with spaces"
94
95rm -f "$GLOBMETACOPY" ${COPY}
96cp $DATA "$GLOBMETACOPY"
97verbose "$tid: get filename with glob metacharacters"
98echo "get \"${GLOBMETACOPY}\" ${COPY}" | \
99	${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 || fail "get failed"
100cmp ${COPY} "$GLOBMETACOPY" || \
101	fail "corrupted copy after get with glob metacharacters"
102
103rm -f ${COPY}.dd/*
104verbose "$tid: get to directory"
105echo "get $DATA ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
106        || fail "get failed"
107cmp $DATA ${COPY}.dd/$DATANAME || fail "corrupted copy after get"
108
109rm -f ${COPY}.dd/*
110verbose "$tid: glob get to directory"
111echo "get /bin/l* ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
112        || fail "get failed"
113for x in $GLOBFILES; do
114        cmp /bin/$x ${COPY}.dd/$x || fail "corrupted copy after get"
115done
116
117rm -f ${COPY}.dd/*
118verbose "$tid: get to local dir"
119(echo "lcd ${COPY}.dd"; echo "get $DATA" ) | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
120        || fail "get failed"
121cmp $DATA ${COPY}.dd/$DATANAME || fail "corrupted copy after get"
122
123rm -f ${COPY}.dd/*
124verbose "$tid: glob get to local dir"
125(echo "lcd ${COPY}.dd"; echo "get /bin/l*") | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
126        || fail "get failed"
127for x in $GLOBFILES; do
128        cmp /bin/$x ${COPY}.dd/$x || fail "corrupted copy after get"
129done
130
131rm -f ${COPY}
132verbose "$tid: put"
133echo "put $DATA $COPY" | \
134	${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 || fail "put failed"
135cmp $DATA ${COPY} || fail "corrupted copy after put"
136
137rm -f ${QUOTECOPY}
138verbose "$tid: put filename with quotes"
139echo "put $DATA \"$QUOTECOPY_ARG\"" | \
140	${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 || fail "put failed"
141cmp $DATA ${QUOTECOPY} || fail "corrupted copy after put with quotes"
142
143rm -f "$SPACECOPY"
144verbose "$tid: put filename with spaces"
145echo "put $DATA ${SPACECOPY_ARG}" | \
146	${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 || fail "put failed"
147cmp $DATA "$SPACECOPY" || fail "corrupted copy after put with spaces"
148
149rm -f ${COPY}.dd/*
150verbose "$tid: put to directory"
151echo "put $DATA ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
152	|| fail "put failed"
153cmp $DATA ${COPY}.dd/$DATANAME || fail "corrupted copy after put"
154
155rm -f ${COPY}.dd/*
156verbose "$tid: glob put to directory"
157echo "put /bin/l? ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
158	|| fail "put failed"
159for x in $GLOBFILES; do
160	cmp /bin/$x ${COPY}.dd/$x || fail "corrupted copy after put"
161done
162
163rm -f ${COPY}.dd/*
164verbose "$tid: put to local dir"
165(echo "cd ${COPY}.dd"; echo "put $DATA") | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
166	|| fail "put failed"
167cmp $DATA ${COPY}.dd/$DATANAME || fail "corrupted copy after put"
168
169rm -f ${COPY}.dd/*
170verbose "$tid: glob put to local dir"
171(echo "cd ${COPY}.dd"; echo "put /bin/l?") | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
172	|| fail "put failed"
173for x in $GLOBFILES; do
174        cmp /bin/$x ${COPY}.dd/$x || fail "corrupted copy after put"
175done
176
177verbose "$tid: rename"
178echo "rename $COPY ${COPY}.1" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
179	|| fail "rename failed"
180test -f ${COPY}.1 || fail "missing file after rename"
181cmp $DATA ${COPY}.1 >/dev/null 2>&1 || fail "corrupted copy after rename"
182
183verbose "$tid: rename directory"
184echo "rename ${COPY}.dd ${COPY}.dd2" | \
185	${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 || \
186	fail "rename directory failed"
187test -d ${COPY}.dd && fail "oldname exists after rename directory"
188test -d ${COPY}.dd2 || fail "missing newname after rename directory"
189
190verbose "$tid: ln"
191echo "ln ${COPY}.1 ${COPY}.2" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 || fail "ln failed"
192test -f ${COPY}.2 || fail "missing file after ln"
193cmp ${COPY}.1 ${COPY}.2 || fail "created file is not equal after ln"
194
195verbose "$tid: ln -s"
196rm -f ${COPY}.2
197echo "ln -s ${COPY}.1 ${COPY}.2" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 || fail "ln -s failed"
198test -h ${COPY}.2 || fail "missing file after ln -s"
199
200verbose "$tid: cp"
201rm -f ${COPY}.2
202echo "cp ${COPY}.1 ${COPY}.2" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 || fail "cp failed"
203cmp ${COPY}.1 ${COPY}.2 || fail "created file is not equal after cp"
204
205verbose "$tid: mkdir"
206echo "mkdir ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
207	|| fail "mkdir failed"
208test -d ${COPY}.dd || fail "missing directory after mkdir"
209
210# XXX do more here
211verbose "$tid: chdir"
212echo "chdir ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
213	|| fail "chdir failed"
214
215verbose "$tid: rmdir"
216echo "rmdir ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
217	|| fail "rmdir failed"
218test -d ${COPY}.1 && fail "present directory after rmdir"
219
220verbose "$tid: lmkdir"
221echo "lmkdir ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
222	|| fail "lmkdir failed"
223test -d ${COPY}.dd || fail "missing directory after lmkdir"
224
225# XXX do more here
226verbose "$tid: lchdir"
227echo "lchdir ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
228	|| fail "lchdir failed"
229
230rm -rf ${COPY} ${COPY}.1 ${COPY}.2 ${COPY}.dd ${COPY}.dd2
231rm -rf ${QUOTECOPY} "$SPACECOPY" "$GLOBMETACOPY"
232
233
234