1# $OpenBSD: sftp-cmds.sh,v 1.6 2003/10/07 07:04:52 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 10DATA=/bin/ls${EXEEXT} 11COPY=${OBJ}/copy 12# test that these files are readable! 13for i in `(cd /bin;echo l*)` 14do 15 if [ -r $i ]; then 16 GLOBFILES="$GLOBFILES $i" 17 fi 18done 19 20if have_prog uname 21then 22 case `uname` in 23 CYGWIN*) 24 os=cygwin 25 ;; 26 *) 27 os=`uname` 28 ;; 29 esac 30else 31 os="unknown" 32fi 33 34# Path with embedded quote 35QUOTECOPY=${COPY}".\"blah\"" 36QUOTECOPY_ARG=${COPY}'.\"blah\"' 37 38rm -rf ${COPY} ${COPY}.1 ${COPY}.2 ${COPY}.dd ${COPY}.dd2 39mkdir ${COPY}.dd 40 41verbose "$tid: lls" 42echo "lls ${OBJ}" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ 43 || fail "lls failed" 44# XXX always successful 45 46verbose "$tid: ls" 47echo "ls ${OBJ}" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ 48 || fail "ls failed" 49# XXX always successful 50 51verbose "$tid: shell" 52echo "!echo hi there" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ 53 || fail "shell failed" 54# XXX always successful 55 56verbose "$tid: pwd" 57echo "pwd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ 58 || fail "pwd failed" 59# XXX always successful 60 61verbose "$tid: lpwd" 62echo "lpwd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ 63 || fail "lpwd failed" 64# XXX always successful 65 66verbose "$tid: quit" 67echo "quit" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ 68 || fail "quit failed" 69# XXX always successful 70 71verbose "$tid: help" 72echo "help" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ 73 || fail "help failed" 74# XXX always successful 75 76rm -f ${COPY} 77verbose "$tid: get" 78echo "get $DATA $COPY" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ 79 || fail "get failed" 80cmp $DATA ${COPY} || fail "corrupted copy after get" 81 82rm -f ${COPY} 83verbose "$tid: get quoted" 84echo "get \"$DATA\" $COPY" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ 85 || fail "get failed" 86cmp $DATA ${COPY} || fail "corrupted copy after get" 87 88if [ "$os" != "cygwin" ]; then 89rm -f ${QUOTECOPY} 90cp $DATA ${QUOTECOPY} 91verbose "$tid: get filename with quotes" 92echo "get \"$QUOTECOPY_ARG\" ${COPY}" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ 93 || fail "put failed" 94cmp ${COPY} ${QUOTECOPY} || fail "corrupted copy after get with quotes" 95rm -f ${QUOTECOPY} ${COPY} 96fi 97 98rm -f ${COPY}.dd/* 99verbose "$tid: get to directory" 100echo "get $DATA ${COPY}.dd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ 101 || fail "get failed" 102cmp $DATA ${COPY}.dd/`basename $DATA` || fail "corrupted copy after get" 103 104rm -f ${COPY}.dd/* 105verbose "$tid: glob get to directory" 106echo "get /bin/l* ${COPY}.dd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ 107 || fail "get failed" 108for x in $GLOBFILES; do 109 cmp /bin/$x ${COPY}.dd/$x || fail "corrupted copy after get" 110done 111 112rm -f ${COPY}.dd/* 113verbose "$tid: get to local dir" 114(echo "lcd ${COPY}.dd"; echo "get $DATA" ) | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ 115 || fail "get failed" 116cmp $DATA ${COPY}.dd/`basename $DATA` || fail "corrupted copy after get" 117 118rm -f ${COPY}.dd/* 119verbose "$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" 122for x in $GLOBFILES; do 123 cmp /bin/$x ${COPY}.dd/$x || fail "corrupted copy after get" 124done 125 126rm -f ${COPY} 127verbose "$tid: put" 128echo "put $DATA $COPY" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ 129 || fail "put failed" 130cmp $DATA ${COPY} || fail "corrupted copy after put" 131 132if [ "$os" != "cygwin" ]; then 133rm -f ${QUOTECOPY} 134verbose "$tid: put filename with quotes" 135echo "put $DATA \"$QUOTECOPY_ARG\"" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ 136 || fail "put failed" 137cmp $DATA ${QUOTECOPY} || fail "corrupted copy after put with quotes" 138fi 139 140rm -f ${COPY}.dd/* 141verbose "$tid: put to directory" 142echo "put $DATA ${COPY}.dd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ 143 || fail "put failed" 144cmp $DATA ${COPY}.dd/`basename $DATA` || fail "corrupted copy after put" 145 146rm -f ${COPY}.dd/* 147verbose "$tid: glob put to directory" 148echo "put /bin/l* ${COPY}.dd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ 149 || fail "put failed" 150for x in $GLOBFILES; do 151 cmp /bin/$x ${COPY}.dd/$x || fail "corrupted copy after put" 152done 153 154rm -f ${COPY}.dd/* 155verbose "$tid: put to local dir" 156(echo "cd ${COPY}.dd"; echo "put $DATA") | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ 157 || fail "put failed" 158cmp $DATA ${COPY}.dd/`basename $DATA` || fail "corrupted copy after put" 159 160rm -f ${COPY}.dd/* 161verbose "$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" 164for x in $GLOBFILES; do 165 cmp /bin/$x ${COPY}.dd/$x || fail "corrupted copy after put" 166done 167 168verbose "$tid: rename" 169echo "rename $COPY ${COPY}.1" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ 170 || fail "rename failed" 171test -f ${COPY}.1 || fail "missing file after rename" 172cmp $DATA ${COPY}.1 >/dev/null 2>&1 || fail "corrupted copy after rename" 173 174verbose "$tid: rename directory" 175echo "rename ${COPY}.dd ${COPY}.dd2" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ 176 || fail "rename directory failed" 177test -d ${COPY}.dd && fail "oldname exists after rename directory" 178test -d ${COPY}.dd2 || fail "missing newname after rename directory" 179 180verbose "$tid: ln" 181echo "ln ${COPY}.1 ${COPY}.2" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 || fail "ln failed" 182test -h ${COPY}.2 || fail "missing file after ln" 183 184verbose "$tid: mkdir" 185echo "mkdir ${COPY}.dd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ 186 || fail "mkdir failed" 187test -d ${COPY}.dd || fail "missing directory after mkdir" 188 189# XXX do more here 190verbose "$tid: chdir" 191echo "chdir ${COPY}.dd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ 192 || fail "chdir failed" 193 194verbose "$tid: rmdir" 195echo "rmdir ${COPY}.dd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ 196 || fail "rmdir failed" 197test -d ${COPY}.1 && fail "present directory after rmdir" 198 199verbose "$tid: lmkdir" 200echo "lmkdir ${COPY}.dd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ 201 || fail "lmkdir failed" 202test -d ${COPY}.dd || fail "missing directory after lmkdir" 203 204# XXX do more here 205verbose "$tid: lchdir" 206echo "lchdir ${COPY}.dd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ 207 || fail "lchdir failed" 208 209rm -rf ${COPY} ${COPY}.1 ${COPY}.2 ${COPY}.dd ${COPY}.dd2 210 211 212