1# $OpenBSD: scp3.sh,v 1.5 2023/09/08 06:10:57 djm Exp $ 2# Placed in the Public Domain. 3 4tid="scp3" 5 6COPY2=${OBJ}/copy2 7DIR=${COPY}.dd 8DIR2=${COPY}.dd2 9 10maybe_add_scp_path_to_sshd 11 12SRC=`dirname ${SCRIPT}` 13cp ${SRC}/scp-ssh-wrapper.sh ${OBJ}/scp-ssh-wrapper.scp 14chmod 755 ${OBJ}/scp-ssh-wrapper.scp 15export SCP # used in scp-ssh-wrapper.scp 16 17scpclean() { 18 rm -rf ${COPY} ${COPY2} ${DIR} ${DIR2} 19 mkdir ${DIR} ${DIR2} 20 chmod 755 ${DIR} ${DIR2} 21} 22 23# Create directory structure for recursive copy tests. 24forest() { 25 scpclean 26 rm -rf ${DIR2} 27 cp ${DATA} ${DIR}/copy 28 ln -s ${DIR}/copy ${DIR}/copy-sym 29 mkdir ${DIR}/subdir 30 cp ${DATA} ${DIR}/subdir/copy 31 ln -s ${DIR}/subdir ${DIR}/subdir-sym 32} 33 34for mode in scp sftp ; do 35 scpopts="-F${OBJ}/ssh_proxy -S ${SSH} -q" 36 tag="$tid: $mode mode" 37 if test $mode = scp ; then 38 scpopts="$scpopts -O" 39 else 40 scpopts="-s -D ${SFTPSERVER}" 41 fi 42 43 verbose "$tag: simple copy remote file to remote file" 44 scpclean 45 $SCP $scpopts -3 hostA:${DATA} hostB:${COPY} || fail "copy failed" 46 cmp ${DATA} ${COPY} || fail "corrupted copy" 47 48 verbose "$tag: simple copy remote file to remote dir" 49 scpclean 50 cp ${DATA} ${COPY} 51 $SCP $scpopts -3 hostA:${COPY} hostB:${DIR} || fail "copy failed" 52 cmp ${COPY} ${DIR}/copy || fail "corrupted copy" 53 54 verbose "$tag: recursive remote dir to remote dir" 55 forest 56 $SCP $scpopts -3r hostA:${DIR} hostB:${DIR2} || fail "copy failed" 57 diff -r ${DIR} ${DIR2} || fail "corrupted copy" 58 diff -r ${DIR2} ${DIR} || fail "corrupted copy" 59 60 verbose "$tag: detect non-directory target" 61 scpclean 62 echo a > ${COPY} 63 echo b > ${COPY2} 64 $SCP $scpopts -3 hostA:${DATA} hostA:${COPY} hostB:${COPY2} 65 cmp ${COPY} ${COPY2} >/dev/null && fail "corrupt target" 66done 67 68scpclean 69rm -f ${OBJ}/scp-ssh-wrapper.exe 70