- (djm) Release 4.6p1
[openssh-git.git] / regress / sftp-cmds.sh
blob31b21d1f2aca82e282f60faf444b2462bc366b6e
1 # $OpenBSD: sftp-cmds.sh,v 1.6 2003/10/07 07:04:52 djm Exp $
2 # Placed in the Public Domain.
4 # XXX - TODO:
5 # - chmod / chown / chgrp
6 # - -p flag for get & put
8 tid="sftp commands"
10 DATA=/bin/ls${EXEEXT}
11 COPY=${OBJ}/copy
12 # test that these files are readable!
13 for i in `(cd /bin;echo l*)`
15 if [ -r $i ]; then
16 GLOBFILES="$GLOBFILES $i"
18 done
20 if have_prog uname
21 then
22 case `uname` in
23 CYGWIN*)
24 os=cygwin
27 os=`uname`
29 esac
30 else
31 os="unknown"
34 # Path with embedded quote
35 QUOTECOPY=${COPY}".\"blah\""
36 QUOTECOPY_ARG=${COPY}'.\"blah\"'
38 rm -rf ${COPY} ${COPY}.1 ${COPY}.2 ${COPY}.dd ${COPY}.dd2
39 mkdir ${COPY}.dd
41 verbose "$tid: lls"
42 echo "lls ${OBJ}" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
43 || fail "lls failed"
44 # XXX always successful
46 verbose "$tid: ls"
47 echo "ls ${OBJ}" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
48 || fail "ls failed"
49 # XXX always successful
51 verbose "$tid: shell"
52 echo "!echo hi there" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
53 || fail "shell failed"
54 # XXX always successful
56 verbose "$tid: pwd"
57 echo "pwd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
58 || fail "pwd failed"
59 # XXX always successful
61 verbose "$tid: lpwd"
62 echo "lpwd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
63 || fail "lpwd failed"
64 # XXX always successful
66 verbose "$tid: quit"
67 echo "quit" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
68 || fail "quit failed"
69 # XXX always successful
71 verbose "$tid: help"
72 echo "help" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
73 || fail "help failed"
74 # XXX always successful
76 rm -f ${COPY}
77 verbose "$tid: get"
78 echo "get $DATA $COPY" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
79 || fail "get failed"
80 cmp $DATA ${COPY} || fail "corrupted copy after get"
82 rm -f ${COPY}
83 verbose "$tid: get quoted"
84 echo "get \"$DATA\" $COPY" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
85 || fail "get failed"
86 cmp $DATA ${COPY} || fail "corrupted copy after get"
88 if [ "$os" != "cygwin" ]; then
89 rm -f ${QUOTECOPY}
90 cp $DATA ${QUOTECOPY}
91 verbose "$tid: get filename with quotes"
92 echo "get \"$QUOTECOPY_ARG\" ${COPY}" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
93 || fail "put failed"
94 cmp ${COPY} ${QUOTECOPY} || fail "corrupted copy after get with quotes"
95 rm -f ${QUOTECOPY} ${COPY}
98 rm -f ${COPY}.dd/*
99 verbose "$tid: get to directory"
100 echo "get $DATA ${COPY}.dd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
101 || fail "get failed"
102 cmp $DATA ${COPY}.dd/`basename $DATA` || fail "corrupted copy after get"
104 rm -f ${COPY}.dd/*
105 verbose "$tid: glob get to directory"
106 echo "get /bin/l* ${COPY}.dd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
107 || fail "get failed"
108 for x in $GLOBFILES; do
109 cmp /bin/$x ${COPY}.dd/$x || fail "corrupted copy after get"
110 done
112 rm -f ${COPY}.dd/*
113 verbose "$tid: get to local dir"
114 (echo "lcd ${COPY}.dd"; echo "get $DATA" ) | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
115 || fail "get failed"
116 cmp $DATA ${COPY}.dd/`basename $DATA` || fail "corrupted copy after get"
118 rm -f ${COPY}.dd/*
119 verbose "$tid: glob get to local dir"
120 (echo "lcd ${COPY}.dd"; echo "get /bin/l*") | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
121 || fail "get failed"
122 for x in $GLOBFILES; do
123 cmp /bin/$x ${COPY}.dd/$x || fail "corrupted copy after get"
124 done
126 rm -f ${COPY}
127 verbose "$tid: put"
128 echo "put $DATA $COPY" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
129 || fail "put failed"
130 cmp $DATA ${COPY} || fail "corrupted copy after put"
132 if [ "$os" != "cygwin" ]; then
133 rm -f ${QUOTECOPY}
134 verbose "$tid: put filename with quotes"
135 echo "put $DATA \"$QUOTECOPY_ARG\"" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
136 || fail "put failed"
137 cmp $DATA ${QUOTECOPY} || fail "corrupted copy after put with quotes"
140 rm -f ${COPY}.dd/*
141 verbose "$tid: put to directory"
142 echo "put $DATA ${COPY}.dd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
143 || fail "put failed"
144 cmp $DATA ${COPY}.dd/`basename $DATA` || fail "corrupted copy after put"
146 rm -f ${COPY}.dd/*
147 verbose "$tid: glob put to directory"
148 echo "put /bin/l* ${COPY}.dd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
149 || fail "put failed"
150 for x in $GLOBFILES; do
151 cmp /bin/$x ${COPY}.dd/$x || fail "corrupted copy after put"
152 done
154 rm -f ${COPY}.dd/*
155 verbose "$tid: put to local dir"
156 (echo "cd ${COPY}.dd"; echo "put $DATA") | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
157 || fail "put failed"
158 cmp $DATA ${COPY}.dd/`basename $DATA` || fail "corrupted copy after put"
160 rm -f ${COPY}.dd/*
161 verbose "$tid: glob put to local dir"
162 (echo "cd ${COPY}.dd"; echo "put /bin/l*") | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
163 || fail "put failed"
164 for x in $GLOBFILES; do
165 cmp /bin/$x ${COPY}.dd/$x || fail "corrupted copy after put"
166 done
168 verbose "$tid: rename"
169 echo "rename $COPY ${COPY}.1" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
170 || fail "rename failed"
171 test -f ${COPY}.1 || fail "missing file after rename"
172 cmp $DATA ${COPY}.1 >/dev/null 2>&1 || fail "corrupted copy after rename"
174 verbose "$tid: rename directory"
175 echo "rename ${COPY}.dd ${COPY}.dd2" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
176 || fail "rename directory failed"
177 test -d ${COPY}.dd && fail "oldname exists after rename directory"
178 test -d ${COPY}.dd2 || fail "missing newname after rename directory"
180 verbose "$tid: ln"
181 echo "ln ${COPY}.1 ${COPY}.2" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 || fail "ln failed"
182 test -h ${COPY}.2 || fail "missing file after ln"
184 verbose "$tid: mkdir"
185 echo "mkdir ${COPY}.dd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
186 || fail "mkdir failed"
187 test -d ${COPY}.dd || fail "missing directory after mkdir"
189 # XXX do more here
190 verbose "$tid: chdir"
191 echo "chdir ${COPY}.dd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
192 || fail "chdir failed"
194 verbose "$tid: rmdir"
195 echo "rmdir ${COPY}.dd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
196 || fail "rmdir failed"
197 test -d ${COPY}.1 && fail "present directory after rmdir"
199 verbose "$tid: lmkdir"
200 echo "lmkdir ${COPY}.dd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
201 || fail "lmkdir failed"
202 test -d ${COPY}.dd || fail "missing directory after lmkdir"
204 # XXX do more here
205 verbose "$tid: lchdir"
206 echo "lchdir ${COPY}.dd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
207 || fail "lchdir failed"
209 rm -rf ${COPY} ${COPY}.1 ${COPY}.2 ${COPY}.dd ${COPY}.dd2