1# $OpenBSD: scp-uri.sh,v 1.5 2023/01/13 04:47:34 dtucker Exp $ 2# Placed in the Public Domain. 3 4tid="scp-uri" 5 6#set -x 7 8COPY2=${OBJ}/copy2 9DIR=${COPY}.dd 10DIR2=${COPY}.dd2 11 12maybe_add_scp_path_to_sshd 13 14SRC=`dirname ${SCRIPT}` 15cp ${SRC}/scp-ssh-wrapper.sh ${OBJ}/scp-ssh-wrapper.scp 16chmod 755 ${OBJ}/scp-ssh-wrapper.scp 17export SCP # used in scp-ssh-wrapper.scp 18 19scpclean() { 20 rm -rf ${COPY} ${COPY2} ${DIR} ${DIR2} 21 mkdir ${DIR} ${DIR2} 22} 23 24# Remove Port and User from ssh_config, we want to rely on the URI 25cp $OBJ/ssh_config $OBJ/ssh_config.orig 26egrep -v '^ +(Port|User) +.*$' $OBJ/ssh_config.orig > $OBJ/ssh_config 27 28for mode in scp sftp ; do 29 tag="$tid: $mode mode" 30 if test $mode = scp ; then 31 scpopts="-O -q -S ${OBJ}/scp-ssh-wrapper.scp" 32 else 33 scpopts="-s -D ${SFTPSERVER}" 34 fi 35 verbose "$tag: simple copy local file to remote file" 36 scpclean 37 $SCP $scpopts ${DATA} "scp://${USER}@somehost:${PORT}/${COPY}" || fail "copy failed" 38 cmp ${DATA} ${COPY} || fail "corrupted copy" 39 40 verbose "$tag: simple copy remote file to local file" 41 scpclean 42 $SCP $scpopts "scp://${USER}@somehost:${PORT}/${DATA}" ${COPY} || fail "copy failed" 43 cmp ${DATA} ${COPY} || fail "corrupted copy" 44 45 verbose "$tag: simple copy local file to remote dir" 46 scpclean 47 cp ${DATA} ${COPY} 48 $SCP $scpopts ${COPY} "scp://${USER}@somehost:${PORT}/${DIR}" || fail "copy failed" 49 cmp ${COPY} ${DIR}/copy || fail "corrupted copy" 50 51 verbose "$tag: simple copy remote file to local dir" 52 scpclean 53 cp ${DATA} ${COPY} 54 $SCP $scpopts "scp://${USER}@somehost:${PORT}/${COPY}" ${DIR} || fail "copy failed" 55 cmp ${COPY} ${DIR}/copy || fail "corrupted copy" 56 57 verbose "$tag: recursive local dir to remote dir" 58 scpclean 59 rm -rf ${DIR2} 60 cp ${DATA} ${DIR}/copy 61 $SCP $scpopts -r ${DIR} "scp://${USER}@somehost:${PORT}/${DIR2}" || fail "copy failed" 62 for i in $(cd ${DIR} && echo *); do 63 cmp ${DIR}/$i ${DIR2}/$i || fail "corrupted copy" 64 done 65 66 verbose "$tag: recursive remote dir to local dir" 67 scpclean 68 rm -rf ${DIR2} 69 cp ${DATA} ${DIR}/copy 70 $SCP $scpopts -r "scp://${USER}@somehost:${PORT}/${DIR}" ${DIR2} || fail "copy failed" 71 for i in $(cd ${DIR} && echo *); do 72 cmp ${DIR}/$i ${DIR2}/$i || fail "corrupted copy" 73 done 74 75 # TODO: scp -3 76done 77 78scpclean 79rm -f ${OBJ}/scp-ssh-wrapper.exe 80