1 # $OpenBSD: sftp-badcmds.sh,v 1.6 2013/05/17 10:26:26 dtucker Exp $
2 # Placed in the Public Domain.
4 tid="sftp invalid commands"
8 GLOBFILES=`(cd /bin;echo l*)`
10 rm -rf ${COPY} ${COPY}.1 ${COPY}.2 ${COPY}.dd
13 verbose "$tid: get nonexistent"
14 echo "get $NONEXIST $COPY" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
15 || fail "get nonexistent failed"
16 test -f ${COPY} && fail "existing copy after get nonexistent"
19 verbose "$tid: glob get to nonexistent directory"
20 echo "get /bin/l* $NONEXIST" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
21 || fail "get nonexistent failed"
22 for x in $GLOBFILES; do
23 test -f ${COPY}.dd/$x && fail "existing copy after get nonexistent"
27 verbose "$tid: put nonexistent"
28 echo "put $NONEXIST $COPY" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
29 || fail "put nonexistent failed"
30 test -f ${COPY} && fail "existing copy after put nonexistent"
33 verbose "$tid: glob put to nonexistent directory"
34 echo "put /bin/l* ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
35 || fail "put nonexistent failed"
36 for x in $GLOBFILES; do
37 test -f ${COPY}.dd/$x && fail "existing copy after nonexistent"
41 verbose "$tid: rename nonexistent"
42 echo "rename $NONEXIST ${COPY}.1" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
43 || fail "rename nonexist failed"
44 test -f ${COPY}.1 && fail "file exists after rename nonexistent"
46 rm -rf ${COPY} ${COPY}.dd
49 verbose "$tid: rename target exists (directory)"
50 echo "rename $COPY ${COPY}.dd" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1 \
51 || fail "rename target exists (directory) failed"
52 test -f ${COPY} || fail "oldname missing after rename target exists (directory)"
53 test -d ${COPY}.dd || fail "newname missing after rename target exists (directory)"
54 cmp $DATA ${COPY} >/dev/null 2>&1 || fail "corrupted oldname after rename target exists (directory)"
59 verbose "$tid: glob put files to local file"
60 echo "put /bin/l* $COPY" | ${SFTP} -D ${SFTPSERVER} >/dev/null 2>&1
61 cmp ${DATA2} ${COPY} || fail "put successed when it should have failed"
63 rm -rf ${COPY} ${COPY}.1 ${COPY}.2 ${COPY}.dd