2023-01-13 04:47:34 +00:00
|
|
|
# $OpenBSD: scp-uri.sh,v 1.5 2023/01/13 04:47:34 dtucker Exp $
|
2017-10-24 19:33:32 +00:00
|
|
|
# Placed in the Public Domain.
|
|
|
|
|
|
|
|
tid="scp-uri"
|
|
|
|
|
|
|
|
#set -x
|
|
|
|
|
|
|
|
COPY2=${OBJ}/copy2
|
|
|
|
DIR=${COPY}.dd
|
|
|
|
DIR2=${COPY}.dd2
|
|
|
|
|
2023-01-13 04:47:34 +00:00
|
|
|
maybe_add_scp_path_to_sshd
|
|
|
|
|
2017-10-24 19:33:32 +00:00
|
|
|
SRC=`dirname ${SCRIPT}`
|
|
|
|
cp ${SRC}/scp-ssh-wrapper.sh ${OBJ}/scp-ssh-wrapper.scp
|
|
|
|
chmod 755 ${OBJ}/scp-ssh-wrapper.scp
|
|
|
|
export SCP # used in scp-ssh-wrapper.scp
|
|
|
|
|
|
|
|
scpclean() {
|
|
|
|
rm -rf ${COPY} ${COPY2} ${DIR} ${DIR2}
|
|
|
|
mkdir ${DIR} ${DIR2}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Remove Port and User from ssh_config, we want to rely on the URI
|
|
|
|
cp $OBJ/ssh_config $OBJ/ssh_config.orig
|
|
|
|
egrep -v '^ +(Port|User) +.*$' $OBJ/ssh_config.orig > $OBJ/ssh_config
|
|
|
|
|
2021-08-03 01:05:24 +00:00
|
|
|
for mode in scp sftp ; do
|
2021-08-10 03:35:45 +00:00
|
|
|
tag="$tid: $mode mode"
|
2021-08-03 01:05:24 +00:00
|
|
|
if test $mode = scp ; then
|
2021-08-10 03:35:45 +00:00
|
|
|
scpopts="-O -q -S ${OBJ}/scp-ssh-wrapper.scp"
|
2021-08-03 01:05:24 +00:00
|
|
|
else
|
2021-08-10 03:35:45 +00:00
|
|
|
scpopts="-s -D ${SFTPSERVER}"
|
2021-08-03 01:05:24 +00:00
|
|
|
fi
|
|
|
|
verbose "$tag: simple copy local file to remote file"
|
|
|
|
scpclean
|
|
|
|
$SCP $scpopts ${DATA} "scp://${USER}@somehost:${PORT}/${COPY}" || fail "copy failed"
|
|
|
|
cmp ${DATA} ${COPY} || fail "corrupted copy"
|
2017-10-24 19:33:32 +00:00
|
|
|
|
2021-08-03 01:05:24 +00:00
|
|
|
verbose "$tag: simple copy remote file to local file"
|
|
|
|
scpclean
|
|
|
|
$SCP $scpopts "scp://${USER}@somehost:${PORT}/${DATA}" ${COPY} || fail "copy failed"
|
|
|
|
cmp ${DATA} ${COPY} || fail "corrupted copy"
|
2017-10-24 19:33:32 +00:00
|
|
|
|
2021-08-03 01:05:24 +00:00
|
|
|
verbose "$tag: simple copy local file to remote dir"
|
|
|
|
scpclean
|
|
|
|
cp ${DATA} ${COPY}
|
|
|
|
$SCP $scpopts ${COPY} "scp://${USER}@somehost:${PORT}/${DIR}" || fail "copy failed"
|
|
|
|
cmp ${COPY} ${DIR}/copy || fail "corrupted copy"
|
2017-10-24 19:33:32 +00:00
|
|
|
|
2021-08-03 01:05:24 +00:00
|
|
|
verbose "$tag: simple copy remote file to local dir"
|
|
|
|
scpclean
|
|
|
|
cp ${DATA} ${COPY}
|
|
|
|
$SCP $scpopts "scp://${USER}@somehost:${PORT}/${COPY}" ${DIR} || fail "copy failed"
|
|
|
|
cmp ${COPY} ${DIR}/copy || fail "corrupted copy"
|
2017-10-24 19:33:32 +00:00
|
|
|
|
2021-08-03 01:05:24 +00:00
|
|
|
verbose "$tag: recursive local dir to remote dir"
|
|
|
|
scpclean
|
|
|
|
rm -rf ${DIR2}
|
|
|
|
cp ${DATA} ${DIR}/copy
|
|
|
|
$SCP $scpopts -r ${DIR} "scp://${USER}@somehost:${PORT}/${DIR2}" || fail "copy failed"
|
|
|
|
for i in $(cd ${DIR} && echo *); do
|
|
|
|
cmp ${DIR}/$i ${DIR2}/$i || fail "corrupted copy"
|
|
|
|
done
|
2017-10-24 19:33:32 +00:00
|
|
|
|
2021-08-03 01:05:24 +00:00
|
|
|
verbose "$tag: recursive remote dir to local dir"
|
|
|
|
scpclean
|
|
|
|
rm -rf ${DIR2}
|
|
|
|
cp ${DATA} ${DIR}/copy
|
|
|
|
$SCP $scpopts -r "scp://${USER}@somehost:${PORT}/${DIR}" ${DIR2} || fail "copy failed"
|
|
|
|
for i in $(cd ${DIR} && echo *); do
|
|
|
|
cmp ${DIR}/$i ${DIR2}/$i || fail "corrupted copy"
|
|
|
|
done
|
2017-10-24 19:33:32 +00:00
|
|
|
|
2021-08-03 01:05:24 +00:00
|
|
|
# TODO: scp -3
|
|
|
|
done
|
2017-10-24 19:33:32 +00:00
|
|
|
|
|
|
|
scpclean
|
|
|
|
rm -f ${OBJ}/scp-ssh-wrapper.exe
|