blob: 31b21d1f2aca82e282f60faf444b2462bc366b6e [file] [log] [blame]
Darren Tucker0240ff72003-10-08 17:52:10 +10001# $OpenBSD: sftp-cmds.sh,v 1.6 2003/10/07 07:04:52 djm Exp $
Damien Miller8b9cde72003-01-22 17:53:16 +11002# Placed in the Public Domain.
3
4# XXX - TODO:
Damien Miller8b9cde72003-01-22 17:53:16 +11005# - chmod / chown / chgrp
6# - -p flag for get & put
7
8tid="sftp commands"
9
Darren Tuckerc2c42232003-09-04 14:54:39 +100010DATA=/bin/ls${EXEEXT}
Damien Miller8b9cde72003-01-22 17:53:16 +110011COPY=${OBJ}/copy
Darren Tucker933e4f12003-09-04 14:26:31 +100012# 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
Tim Rice23ee3592003-09-11 22:32:17 -070020if have_prog uname
Darren Tuckere7f75802003-09-07 09:32:58 +100021then
22 case `uname` in
23 CYGWIN*)
24 os=cygwin
25 ;;
26 *)
27 os=`uname`
28 ;;
29 esac
30else
31 os="unknown"
32fi
33
Darren Tuckercca1bdb2003-07-19 20:11:54 +100034# Path with embedded quote
35QUOTECOPY=${COPY}".\"blah\""
36QUOTECOPY_ARG=${COPY}'.\"blah\"'
37
Tim Rice1eb40cf2003-09-09 08:35:20 -070038rm -rf ${COPY} ${COPY}.1 ${COPY}.2 ${COPY}.dd ${COPY}.dd2
Darren Tuckerc43362c2003-06-18 22:41:41 +100039mkdir ${COPY}.dd
Damien Miller8b9cde72003-01-22 17:53:16 +110040
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
Darren Tucker0240ff72003-10-08 17:52:10 +100082rm -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
Darren Tuckerc99a19b2004-04-16 17:58:28 +100088if [ "$os" != "cygwin" ]; then
Darren Tucker0240ff72003-10-08 17:52:10 +100089rm -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}
Darren Tuckerc99a19b2004-04-16 17:58:28 +100096fi
Darren Tucker0240ff72003-10-08 17:52:10 +100097
Darren Tuckerc43362c2003-06-18 22:41:41 +100098rm -f ${COPY}.dd/*
99verbose "$tid: get to directory"
100echo "get $DATA ${COPY}.dd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
101 || fail "get failed"
Darren Tuckerc2c42232003-09-04 14:54:39 +1000102cmp $DATA ${COPY}.dd/`basename $DATA` || fail "corrupted copy after get"
Darren Tuckerc43362c2003-06-18 22:41:41 +1000103
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"
Darren Tuckerc2c42232003-09-04 14:54:39 +1000114(echo "lcd ${COPY}.dd"; echo "get $DATA" ) | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
Darren Tuckerc43362c2003-06-18 22:41:41 +1000115 || fail "get failed"
Darren Tuckerc2c42232003-09-04 14:54:39 +1000116cmp $DATA ${COPY}.dd/`basename $DATA` || fail "corrupted copy after get"
Darren Tuckerc43362c2003-06-18 22:41:41 +1000117
118rm -f ${COPY}.dd/*
119verbose "$tid: glob get to local dir"
Darren Tuckerc2c42232003-09-04 14:54:39 +1000120(echo "lcd ${COPY}.dd"; echo "get /bin/l*") | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
Darren Tuckerc43362c2003-06-18 22:41:41 +1000121 || fail "get failed"
122for x in $GLOBFILES; do
123 cmp /bin/$x ${COPY}.dd/$x || fail "corrupted copy after get"
124done
125
Damien Miller8b9cde72003-01-22 17:53:16 +1100126rm -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
Darren Tuckere7f75802003-09-07 09:32:58 +1000132if [ "$os" != "cygwin" ]; then
Darren Tuckercca1bdb2003-07-19 20:11:54 +1000133rm -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"
Darren Tuckere7f75802003-09-07 09:32:58 +1000138fi
Darren Tuckercca1bdb2003-07-19 20:11:54 +1000139
Darren Tuckerc43362c2003-06-18 22:41:41 +1000140rm -f ${COPY}.dd/*
141verbose "$tid: put to directory"
142echo "put $DATA ${COPY}.dd" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
143 || fail "put failed"
Darren Tuckerc2c42232003-09-04 14:54:39 +1000144cmp $DATA ${COPY}.dd/`basename $DATA` || fail "corrupted copy after put"
Darren Tuckerc43362c2003-06-18 22:41:41 +1000145
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"
Darren Tuckerc2c42232003-09-04 14:54:39 +1000156(echo "cd ${COPY}.dd"; echo "put $DATA") | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
Darren Tuckerc43362c2003-06-18 22:41:41 +1000157 || fail "put failed"
Darren Tuckerc2c42232003-09-04 14:54:39 +1000158cmp $DATA ${COPY}.dd/`basename $DATA` || fail "corrupted copy after put"
Darren Tuckerc43362c2003-06-18 22:41:41 +1000159
160rm -f ${COPY}.dd/*
161verbose "$tid: glob put to local dir"
Darren Tuckerc2c42232003-09-04 14:54:39 +1000162(echo "cd ${COPY}.dd"; echo "put /bin/l*") | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 \
Darren Tuckerc43362c2003-06-18 22:41:41 +1000163 || fail "put failed"
164for x in $GLOBFILES; do
165 cmp /bin/$x ${COPY}.dd/$x || fail "corrupted copy after put"
166done
167
Damien Miller8b9cde72003-01-22 17:53:16 +1100168verbose "$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
Darren Tuckera4040f52003-06-18 22:35:11 +1000174verbose "$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
Damien Miller8b9cde72003-01-22 17:53:16 +1100180verbose "$tid: ln"
181echo "ln ${COPY}.1 ${COPY}.2" | ${SFTP} -P ${SFTPSERVER} >/dev/null 2>&1 || fail "ln failed"
Darren Tucker47351152003-09-04 15:24:50 +1000182test -h ${COPY}.2 || fail "missing file after ln"
Damien Miller8b9cde72003-01-22 17:53:16 +1100183
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
Tim Rice1eb40cf2003-09-09 08:35:20 -0700209rm -rf ${COPY} ${COPY}.1 ${COPY}.2 ${COPY}.dd ${COPY}.dd2
Damien Miller8b9cde72003-01-22 17:53:16 +1100210
211