1 # $OpenBSD: sftp-cmds.sh,v 1.6 2003/10/07 07:04:52 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 rm -rf ${COPY} ${COPY}.1 ${COPY}.2 ${COPY}.dd ${COPY}.dd2
42 echo "lls ${OBJ}" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
44 # XXX always successful
47 echo "ls ${OBJ}" | ${SFTP} -P ${SFTPSERVER} >/dev
/null
2>&1 \
49 # XXX always successful
52 echo "!echo hi there" |
${SFTP} -P ${SFTPSERVER} >/dev
/null
2>&1 \
53 || fail
"shell failed"
54 # XXX always successful
57 echo "pwd" |
${SFTP} -P ${SFTPSERVER} >/dev
/null
2>&1 \
59 # XXX always successful
62 echo "lpwd" |
${SFTP} -P ${SFTPSERVER} >/dev
/null
2>&1 \
64 # XXX always successful
67 echo "quit" |
${SFTP} -P ${SFTPSERVER} >/dev
/null
2>&1 \
69 # XXX always successful
72 echo "help" |
${SFTP} -P ${SFTPSERVER} >/dev
/null
2>&1 \
74 # XXX always successful
78 echo "get $DATA $COPY" |
${SFTP} -P ${SFTPSERVER} >/dev
/null
2>&1 \
80 cmp $DATA ${COPY} || fail
"corrupted copy after get"
83 verbose
"$tid: get quoted"
84 echo "get \"$DATA\" $COPY" |
${SFTP} -P ${SFTPSERVER} >/dev
/null
2>&1 \
86 cmp $DATA ${COPY} || fail
"corrupted copy after get"
88 if [ "$os" != "cygwin" ]; then
91 verbose
"$tid: get filename with quotes"
92 echo "get \"$QUOTECOPY_ARG\" ${COPY}" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
94 cmp ${COPY} ${QUOTECOPY} || fail "corrupted copy after get with quotes
"
95 rm -f ${QUOTECOPY} ${COPY}
99 verbose "$tid: get to directory
"
100 echo "get
$DATA ${COPY}.dd" | ${SFTP} -P ${SFTPSERVER} >/dev
/null
2>&1 \
102 cmp $DATA ${COPY}.dd
/`basename $DATA` || fail
"corrupted copy after get"
105 verbose
"$tid: glob get to directory"
106 echo "get /bin/l* ${COPY}.dd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
108 for x in $GLOBFILES; do
109 cmp /bin/$x ${COPY}.dd/$x || fail "corrupted copy after get
"
113 verbose "$tid: get to
local dir
"
114 (echo "lcd
${COPY}.dd"; echo "get $DATA" ) | ${SFTP} -P ${SFTPSERVER} >/dev
/null
2>&1 \
116 cmp $DATA ${COPY}.dd
/`basename $DATA` || fail
"corrupted copy after get"
119 verbose
"$tid: glob get to local dir"
120 (echo "lcd ${COPY}.dd"; echo "get /bin/l*") | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
122 for x in $GLOBFILES; do
123 cmp /bin/$x ${COPY}.dd/$x || fail "corrupted copy after get
"
128 echo "put
$DATA $COPY" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
130 cmp $DATA ${COPY} || fail "corrupted copy after put
"
132 if [ "$os" != "cygwin
" ]; then
134 verbose "$tid: put filename with quotes
"
135 echo "put
$DATA \"$QUOTECOPY_ARG\"" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
137 cmp $DATA ${QUOTECOPY} || fail "corrupted copy after put with quotes
"
141 verbose "$tid: put to directory
"
142 echo "put
$DATA ${COPY}.dd" | ${SFTP} -P ${SFTPSERVER} >/dev
/null
2>&1 \
144 cmp $DATA ${COPY}.dd
/`basename $DATA` || fail
"corrupted copy after put"
147 verbose
"$tid: glob put to directory"
148 echo "put /bin/l* ${COPY}.dd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
150 for x in $GLOBFILES; do
151 cmp /bin/$x ${COPY}.dd/$x || fail "corrupted copy after put
"
155 verbose "$tid: put to
local dir
"
156 (echo "cd ${COPY}.dd"; echo "put $DATA") | ${SFTP} -P ${SFTPSERVER} >/dev
/null
2>&1 \
158 cmp $DATA ${COPY}.dd
/`basename $DATA` || fail
"corrupted copy after put"
161 verbose
"$tid: glob put to local dir"
162 (echo "cd ${COPY}.dd"; echo "put /bin/l*") | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
164 for x in $GLOBFILES; do
165 cmp /bin/$x ${COPY}.dd/$x || fail "corrupted copy after put
"
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
"
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
"
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"
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