Darren Tucker | 0240ff7 | 2003-10-08 17:52:10 +1000 | [diff] [blame] | 1 | # $OpenBSD: sftp-cmds.sh,v 1.6 2003/10/07 07:04:52 djm Exp $ |
Damien Miller | 8b9cde7 | 2003-01-22 17:53:16 +1100 | [diff] [blame] | 2 | # Placed in the Public Domain. |
| 3 | |
| 4 | # XXX - TODO: |
Damien Miller | 8b9cde7 | 2003-01-22 17:53:16 +1100 | [diff] [blame] | 5 | # - chmod / chown / chgrp |
| 6 | # - -p flag for get & put |
| 7 | |
| 8 | tid="sftp commands" |
| 9 | |
Darren Tucker | c2c4223 | 2003-09-04 14:54:39 +1000 | [diff] [blame] | 10 | DATA=/bin/ls${EXEEXT} |
Damien Miller | 8b9cde7 | 2003-01-22 17:53:16 +1100 | [diff] [blame] | 11 | COPY=${OBJ}/copy |
Darren Tucker | 933e4f1 | 2003-09-04 14:26:31 +1000 | [diff] [blame] | 12 | # test that these files are readable! |
| 13 | for i in `(cd /bin;echo l*)` |
| 14 | do |
| 15 | if [ -r $i ]; then |
| 16 | GLOBFILES="$GLOBFILES $i" |
| 17 | fi |
| 18 | done |
| 19 | |
Tim Rice | 23ee359 | 2003-09-11 22:32:17 -0700 | [diff] [blame] | 20 | if have_prog uname |
Darren Tucker | e7f7580 | 2003-09-07 09:32:58 +1000 | [diff] [blame] | 21 | then |
| 22 | case `uname` in |
| 23 | CYGWIN*) |
| 24 | os=cygwin |
| 25 | ;; |
| 26 | *) |
| 27 | os=`uname` |
| 28 | ;; |
| 29 | esac |
| 30 | else |
| 31 | os="unknown" |
| 32 | fi |
| 33 | |
Darren Tucker | cca1bdb | 2003-07-19 20:11:54 +1000 | [diff] [blame] | 34 | # Path with embedded quote |
| 35 | QUOTECOPY=${COPY}".\"blah\"" |
| 36 | QUOTECOPY_ARG=${COPY}'.\"blah\"' |
| 37 | |
Tim Rice | 1eb40cf | 2003-09-09 08:35:20 -0700 | [diff] [blame] | 38 | rm -rf ${COPY} ${COPY}.1 ${COPY}.2 ${COPY}.dd ${COPY}.dd2 |
Darren Tucker | c43362c | 2003-06-18 22:41:41 +1000 | [diff] [blame] | 39 | mkdir ${COPY}.dd |
Damien Miller | 8b9cde7 | 2003-01-22 17:53:16 +1100 | [diff] [blame] | 40 | |
| 41 | verbose "$tid: lls" |
| 42 | echo "lls ${OBJ}" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ |
| 43 | || fail "lls failed" |
| 44 | # XXX always successful |
| 45 | |
| 46 | verbose "$tid: ls" |
| 47 | echo "ls ${OBJ}" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ |
| 48 | || fail "ls failed" |
| 49 | # XXX always successful |
| 50 | |
| 51 | verbose "$tid: shell" |
| 52 | echo "!echo hi there" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ |
| 53 | || fail "shell failed" |
| 54 | # XXX always successful |
| 55 | |
| 56 | verbose "$tid: pwd" |
| 57 | echo "pwd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ |
| 58 | || fail "pwd failed" |
| 59 | # XXX always successful |
| 60 | |
| 61 | verbose "$tid: lpwd" |
| 62 | echo "lpwd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ |
| 63 | || fail "lpwd failed" |
| 64 | # XXX always successful |
| 65 | |
| 66 | verbose "$tid: quit" |
| 67 | echo "quit" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ |
| 68 | || fail "quit failed" |
| 69 | # XXX always successful |
| 70 | |
| 71 | verbose "$tid: help" |
| 72 | echo "help" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ |
| 73 | || fail "help failed" |
| 74 | # XXX always successful |
| 75 | |
| 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" |
| 81 | |
Darren Tucker | 0240ff7 | 2003-10-08 17:52:10 +1000 | [diff] [blame] | 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" |
| 87 | |
Darren Tucker | c99a19b | 2004-04-16 17:58:28 +1000 | [diff] [blame] | 88 | if [ "$os" != "cygwin" ]; then |
Darren Tucker | 0240ff7 | 2003-10-08 17:52:10 +1000 | [diff] [blame] | 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} |
Darren Tucker | c99a19b | 2004-04-16 17:58:28 +1000 | [diff] [blame] | 96 | fi |
Darren Tucker | 0240ff7 | 2003-10-08 17:52:10 +1000 | [diff] [blame] | 97 | |
Darren Tucker | c43362c | 2003-06-18 22:41:41 +1000 | [diff] [blame] | 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" |
Darren Tucker | c2c4223 | 2003-09-04 14:54:39 +1000 | [diff] [blame] | 102 | cmp $DATA ${COPY}.dd/`basename $DATA` || fail "corrupted copy after get" |
Darren Tucker | c43362c | 2003-06-18 22:41:41 +1000 | [diff] [blame] | 103 | |
| 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 |
| 111 | |
| 112 | rm -f ${COPY}.dd/* |
| 113 | verbose "$tid: get to local dir" |
Darren Tucker | c2c4223 | 2003-09-04 14:54:39 +1000 | [diff] [blame] | 114 | (echo "lcd ${COPY}.dd"; echo "get $DATA" ) | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ |
Darren Tucker | c43362c | 2003-06-18 22:41:41 +1000 | [diff] [blame] | 115 | || fail "get failed" |
Darren Tucker | c2c4223 | 2003-09-04 14:54:39 +1000 | [diff] [blame] | 116 | cmp $DATA ${COPY}.dd/`basename $DATA` || fail "corrupted copy after get" |
Darren Tucker | c43362c | 2003-06-18 22:41:41 +1000 | [diff] [blame] | 117 | |
| 118 | rm -f ${COPY}.dd/* |
| 119 | verbose "$tid: glob get to local dir" |
Darren Tucker | c2c4223 | 2003-09-04 14:54:39 +1000 | [diff] [blame] | 120 | (echo "lcd ${COPY}.dd"; echo "get /bin/l*") | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ |
Darren Tucker | c43362c | 2003-06-18 22:41:41 +1000 | [diff] [blame] | 121 | || fail "get failed" |
| 122 | for x in $GLOBFILES; do |
| 123 | cmp /bin/$x ${COPY}.dd/$x || fail "corrupted copy after get" |
| 124 | done |
| 125 | |
Damien Miller | 8b9cde7 | 2003-01-22 17:53:16 +1100 | [diff] [blame] | 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" |
| 131 | |
Darren Tucker | e7f7580 | 2003-09-07 09:32:58 +1000 | [diff] [blame] | 132 | if [ "$os" != "cygwin" ]; then |
Darren Tucker | cca1bdb | 2003-07-19 20:11:54 +1000 | [diff] [blame] | 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" |
Darren Tucker | e7f7580 | 2003-09-07 09:32:58 +1000 | [diff] [blame] | 138 | fi |
Darren Tucker | cca1bdb | 2003-07-19 20:11:54 +1000 | [diff] [blame] | 139 | |
Darren Tucker | c43362c | 2003-06-18 22:41:41 +1000 | [diff] [blame] | 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" |
Darren Tucker | c2c4223 | 2003-09-04 14:54:39 +1000 | [diff] [blame] | 144 | cmp $DATA ${COPY}.dd/`basename $DATA` || fail "corrupted copy after put" |
Darren Tucker | c43362c | 2003-06-18 22:41:41 +1000 | [diff] [blame] | 145 | |
| 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 |
| 153 | |
| 154 | rm -f ${COPY}.dd/* |
| 155 | verbose "$tid: put to local dir" |
Darren Tucker | c2c4223 | 2003-09-04 14:54:39 +1000 | [diff] [blame] | 156 | (echo "cd ${COPY}.dd"; echo "put $DATA") | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ |
Darren Tucker | c43362c | 2003-06-18 22:41:41 +1000 | [diff] [blame] | 157 | || fail "put failed" |
Darren Tucker | c2c4223 | 2003-09-04 14:54:39 +1000 | [diff] [blame] | 158 | cmp $DATA ${COPY}.dd/`basename $DATA` || fail "corrupted copy after put" |
Darren Tucker | c43362c | 2003-06-18 22:41:41 +1000 | [diff] [blame] | 159 | |
| 160 | rm -f ${COPY}.dd/* |
| 161 | verbose "$tid: glob put to local dir" |
Darren Tucker | c2c4223 | 2003-09-04 14:54:39 +1000 | [diff] [blame] | 162 | (echo "cd ${COPY}.dd"; echo "put /bin/l*") | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \ |
Darren Tucker | c43362c | 2003-06-18 22:41:41 +1000 | [diff] [blame] | 163 | || fail "put failed" |
| 164 | for x in $GLOBFILES; do |
| 165 | cmp /bin/$x ${COPY}.dd/$x || fail "corrupted copy after put" |
| 166 | done |
| 167 | |
Damien Miller | 8b9cde7 | 2003-01-22 17:53:16 +1100 | [diff] [blame] | 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" |
| 173 | |
Darren Tucker | a4040f5 | 2003-06-18 22:35:11 +1000 | [diff] [blame] | 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" |
| 179 | |
Damien Miller | 8b9cde7 | 2003-01-22 17:53:16 +1100 | [diff] [blame] | 180 | verbose "$tid: ln" |
| 181 | echo "ln ${COPY}.1 ${COPY}.2" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 || fail "ln failed" |
Darren Tucker | 4735115 | 2003-09-04 15:24:50 +1000 | [diff] [blame] | 182 | test -h ${COPY}.2 || fail "missing file after ln" |
Damien Miller | 8b9cde7 | 2003-01-22 17:53:16 +1100 | [diff] [blame] | 183 | |
| 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" |
| 188 | |
| 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" |
| 193 | |
| 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" |
| 198 | |
| 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" |
| 203 | |
| 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" |
| 208 | |
Tim Rice | 1eb40cf | 2003-09-09 08:35:20 -0700 | [diff] [blame] | 209 | rm -rf ${COPY} ${COPY}.1 ${COPY}.2 ${COPY}.dd ${COPY}.dd2 |
Damien Miller | 8b9cde7 | 2003-01-22 17:53:16 +1100 | [diff] [blame] | 210 | |
| 211 | |