1 # $OpenBSD: sftp-cmds.sh,v 1.10 2009/08/13 01:11:55 djm Exp $
2 # Placed in the Public Domain.
5 # - chmod / chown / chgrp
6 # - -p flag for get & put
12 # test that these files are readable!
13 for i
in `(cd /bin;echo l*)`
16 GLOBFILES
="$GLOBFILES $i"
34 # Path with embedded quote
35 QUOTECOPY
=${COPY}".\"blah\""
36 QUOTECOPY_ARG
=${COPY}'.\"blah\"'
38 SPACECOPY
="${COPY} this has spaces.txt"
39 SPACECOPY_ARG
="${COPY}\ this\ has\ spaces.txt"
40 # File with glob metacharacters
41 GLOBMETACOPY
="${COPY} [metachar].txt"
43 rm -rf ${COPY} ${COPY}.1 ${COPY}.2 ${COPY}.dd ${COPY}.dd2 ${BATCH}.
*
47 (echo "lcd ${OBJ}" ; echo "lls") | ${SFTP} -D ${SFTPSERVER} 2>&1 | \
48 grep copy.dd >/dev/null 2>&1 || fail "lls failed
"
50 verbose "$tid: lls w
/path
"
51 echo "lls
${OBJ}" | ${SFTP} -D ${SFTPSERVER} 2>&1 | \
52 grep copy.
dd >/dev
/null
2>&1 || fail
"lls w/path failed"
55 echo "ls ${OBJ}" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
57 # XXX always successful
60 echo "!echo hi there
" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
61 || fail "shell failed
"
62 # XXX always successful
65 echo "pwd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
67 # XXX always successful
70 echo "lpwd
" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
72 # XXX always successful
75 echo "quit
" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
77 # XXX always successful
80 echo "help" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
82 # XXX always successful
86 echo "get
$DATA $COPY" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
88 cmp $DATA ${COPY} || fail "corrupted copy after get
"
91 verbose "$tid: get quoted
"
92 echo "get
\"$DATA\" $COPY" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
94 cmp $DATA ${COPY} || fail "corrupted copy after get
"
96 if [ "$os" != "cygwin
" ]; then
99 verbose "$tid: get filename with quotes
"
100 echo "get
\"$QUOTECOPY_ARG\" ${COPY}" | ${SFTP} -D ${SFTPSERVER} >/dev
/null
2>&1 \
102 cmp ${COPY} ${QUOTECOPY} || fail
"corrupted copy after get with quotes"
103 rm -f ${QUOTECOPY} ${COPY}
106 rm -f "$SPACECOPY" ${COPY}
107 cp $DATA "$SPACECOPY"
108 verbose
"$tid: get filename with spaces"
109 echo "get ${SPACECOPY_ARG} ${COPY}" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
111 cmp ${COPY} "$SPACECOPY" || fail "corrupted copy after get with spaces
"
113 rm -f "$GLOBMETACOPY" ${COPY}
114 cp $DATA "$GLOBMETACOPY"
115 verbose "$tid: get filename with glob metacharacters
"
116 echo "get
\"${GLOBMETACOPY}\" ${COPY}" | \
117 ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 || fail "get failed
"
118 cmp ${COPY} "$GLOBMETACOPY" || \
119 fail "corrupted copy after get with glob metacharacters
"
122 verbose "$tid: get to directory
"
123 echo "get
$DATA ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev
/null
2>&1 \
125 cmp $DATA ${COPY}.dd
/`basename $DATA` || fail
"corrupted copy after get"
128 verbose
"$tid: glob get to directory"
129 echo "get /bin/l* ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
131 for x in $GLOBFILES; do
132 cmp /bin/$x ${COPY}.dd/$x || fail "corrupted copy after get
"
136 verbose "$tid: get to
local dir
"
137 (echo "lcd
${COPY}.dd"; echo "get $DATA" ) | ${SFTP} -D ${SFTPSERVER} >/dev
/null
2>&1 \
139 cmp $DATA ${COPY}.dd
/`basename $DATA` || fail
"corrupted copy after get"
142 verbose
"$tid: glob get to local dir"
143 (echo "lcd ${COPY}.dd"; echo "get /bin/l*") | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
145 for x in $GLOBFILES; do
146 cmp /bin/$x ${COPY}.dd/$x || fail "corrupted copy after get
"
151 echo "put
$DATA $COPY" | \
152 ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 || fail "put failed
"
153 cmp $DATA ${COPY} || fail "corrupted copy after put
"
155 if [ "$os" != "cygwin
" ]; then
157 verbose "$tid: put filename with quotes
"
158 echo "put
$DATA \"$QUOTECOPY_ARG\"" | \
159 ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 || fail "put failed
"
160 cmp $DATA ${QUOTECOPY} || fail "corrupted copy after put with quotes
"
164 verbose "$tid: put filename with spaces
"
165 echo "put
$DATA ${SPACECOPY_ARG}" | \
166 ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 || fail "put failed
"
167 cmp $DATA "$SPACECOPY" || fail "corrupted copy after put with spaces
"
170 verbose "$tid: put to directory
"
171 echo "put
$DATA ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev
/null
2>&1 \
173 cmp $DATA ${COPY}.dd
/`basename $DATA` || fail
"corrupted copy after put"
176 verbose
"$tid: glob put to directory"
177 echo "put /bin/l? ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
179 for x in $GLOBFILES; do
180 cmp /bin/$x ${COPY}.dd/$x || fail "corrupted copy after put
"
184 verbose "$tid: put to
local dir
"
185 (echo "cd ${COPY}.dd"; echo "put $DATA") | ${SFTP} -D ${SFTPSERVER} >/dev
/null
2>&1 \
187 cmp $DATA ${COPY}.dd
/`basename $DATA` || fail
"corrupted copy after put"
190 verbose
"$tid: glob put to local dir"
191 (echo "cd ${COPY}.dd"; echo "put /bin/l?") | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
193 for x in $GLOBFILES; do
194 cmp /bin/$x ${COPY}.dd/$x || fail "corrupted copy after put
"
197 verbose "$tid: rename
"
198 echo "rename
$COPY ${COPY}.1" | ${SFTP} -D ${SFTPSERVER} >/dev
/null
2>&1 \
199 || fail
"rename failed"
200 test -f ${COPY}.1 || fail
"missing file after rename"
201 cmp $DATA ${COPY}.1 >/dev
/null
2>&1 || fail
"corrupted copy after rename"
203 verbose
"$tid: rename directory"
204 echo "rename ${COPY}.dd ${COPY}.dd2" | \
205 ${SFTP} -D ${SFTPSERVER} >/dev
/null
2>&1 || \
206 fail
"rename directory failed"
207 test -d ${COPY}.
dd && fail
"oldname exists after rename directory"
208 test -d ${COPY}.dd2 || fail
"missing newname after rename directory"
211 echo "ln ${COPY}.1 ${COPY}.2" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 || fail "ln failed
"
212 test -h ${COPY}.2 || fail "missing
file after
ln"
214 verbose "$tid: mkdir
"
215 echo "mkdir
${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev
/null
2>&1 \
216 || fail
"mkdir failed"
217 test -d ${COPY}.
dd || fail
"missing directory after mkdir"
220 verbose
"$tid: chdir"
221 echo "chdir ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
222 || fail "chdir failed
"
224 verbose "$tid: rmdir"
225 echo "rmdir ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev
/null
2>&1 \
226 || fail
"rmdir failed"
227 test -d ${COPY}.1 && fail
"present directory after rmdir"
229 verbose
"$tid: lmkdir"
230 echo "lmkdir ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
231 || fail "lmkdir failed
"
232 test -d ${COPY}.dd || fail "missing directory after lmkdir
"
235 verbose "$tid: lchdir
"
236 echo "lchdir
${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev
/null
2>&1 \
237 || fail
"lchdir failed"
239 rm -rf ${COPY} ${COPY}.1 ${COPY}.2 ${COPY}.dd ${COPY}.dd2 ${BATCH}.
*
240 rm -rf ${QUOTECOPY} "$SPACECOPY" "$GLOBMETACOPY"