Darren Tucker | 6f0e35b | 2004-06-16 23:22:37 +1000 | [diff] [blame^] | 1 | # $OpenBSD: scp.sh,v 1.2 2004/06/16 13:15:09 dtucker Exp $ |
Darren Tucker | 50433a9 | 2004-06-16 20:15:59 +1000 | [diff] [blame] | 2 | # Placed in the Public Domain. |
| 3 | |
| 4 | tid="scp" |
| 5 | |
| 6 | #set -x |
| 7 | |
| 8 | DATA=/bin/ls |
| 9 | COPY=${OBJ}/copy |
| 10 | COPY2=${OBJ}/copy2 |
| 11 | DIR=${COPY}.dd |
| 12 | DIR2=${COPY}.dd2 |
| 13 | |
| 14 | SRC=`dirname ${SCRIPT}` |
| 15 | cp ${SRC}/scp-ssh-wrapper.sh ${OBJ}/scp-ssh-wrapper.exe |
| 16 | chmod 755 ${OBJ}/scp-ssh-wrapper.exe |
| 17 | scpopts="-q -S ${OBJ}/scp-ssh-wrapper.exe" |
| 18 | |
| 19 | scpclean() { |
| 20 | rm -rf ${COPY} ${COPY2} ${DIR} ${DIR2} |
| 21 | mkdir ${DIR} ${DIR2} |
| 22 | } |
| 23 | |
| 24 | verbose "$tid: simple copy local file to remote file" |
| 25 | scpclean |
| 26 | $SCP $scpopts ${DATA} somehost:${COPY} || fail "copy failed" |
| 27 | cmp ${DATA} ${COPY} || fail "corrupted copy" |
| 28 | |
| 29 | verbose "$tid: simple copy remote file to local file" |
| 30 | scpclean |
| 31 | $SCP $scpopts somehost:${DATA} ${COPY} || fail "copy failed" |
| 32 | cmp ${DATA} ${COPY} || fail "corrupted copy" |
| 33 | |
| 34 | verbose "$tid: simple copy local file to remote dir" |
| 35 | scpclean |
| 36 | cp ${DATA} ${COPY} |
| 37 | $SCP $scpopts ${COPY} somehost:${DIR} || fail "copy failed" |
| 38 | cmp ${COPY} ${DIR}/copy || fail "corrupted copy" |
| 39 | |
| 40 | verbose "$tid: simple copy remote file to local dir" |
| 41 | scpclean |
| 42 | cp ${DATA} ${COPY} |
| 43 | $SCP $scpopts somehost:${COPY} ${DIR} || fail "copy failed" |
| 44 | cmp ${COPY} ${DIR}/copy || fail "corrupted copy" |
| 45 | |
| 46 | verbose "$tid: recursive local dir to remote dir" |
| 47 | scpclean |
Darren Tucker | 6f0e35b | 2004-06-16 23:22:37 +1000 | [diff] [blame^] | 48 | rm -rf ${DIR2} |
Darren Tucker | 50433a9 | 2004-06-16 20:15:59 +1000 | [diff] [blame] | 49 | cp ${DATA} ${DIR}/copy |
| 50 | $SCP $scpopts -r ${DIR} somehost:${DIR2} || fail "copy failed" |
Darren Tucker | 6f0e35b | 2004-06-16 23:22:37 +1000 | [diff] [blame^] | 51 | diff -rN ${DIR} ${DIR2} || fail "corrupted copy" |
Darren Tucker | 50433a9 | 2004-06-16 20:15:59 +1000 | [diff] [blame] | 52 | |
| 53 | verbose "$tid: recursive remote dir to local dir" |
| 54 | scpclean |
Darren Tucker | 6f0e35b | 2004-06-16 23:22:37 +1000 | [diff] [blame^] | 55 | rm -rf ${DIR2} |
Darren Tucker | 50433a9 | 2004-06-16 20:15:59 +1000 | [diff] [blame] | 56 | cp ${DATA} ${DIR}/copy |
| 57 | $SCP $scpopts -r somehost:${DIR} ${DIR2} || fail "copy failed" |
Darren Tucker | 6f0e35b | 2004-06-16 23:22:37 +1000 | [diff] [blame^] | 58 | diff -rN ${DIR} ${DIR2} || fail "corrupted copy" |
Darren Tucker | 50433a9 | 2004-06-16 20:15:59 +1000 | [diff] [blame] | 59 | |
| 60 | for i in 0 1 2 3 4; do |
| 61 | verbose "$tid: disallow bad server #$i" |
| 62 | SCPTESTMODE=badserver_$i |
| 63 | export DIR SCPTESTMODE |
| 64 | scpclean |
| 65 | $SCP $scpopts somehost:${DATA} ${DIR} >/dev/null 2>/dev/null |
| 66 | [ -d {$DIR}/rootpathdir ] && fail "allows dir relative to root dir" |
| 67 | [ -d ${DIR}/dotpathdir ] && fail "allows dir creation in non-recursive mode" |
| 68 | |
| 69 | scpclean |
| 70 | $SCP -r $scpopts somehost:${DATA} ${DIR2} >/dev/null 2>/dev/null |
| 71 | [ -d ${DIR}/dotpathdir ] && fail "allows dir creation outside of subdir" |
| 72 | done |
| 73 | |
| 74 | scpclean |
| 75 | rm -f ${OBJ}/scp-ssh-wrapper.exe |