xref: /freebsd/crypto/openssh/regress/scp3.sh (revision 924226fba12cc9a228c73b956e1b7fa24c60b055)
1#	$OpenBSD: scp3.sh,v 1.3 2021/08/10 03:35:45 djm Exp $
2#	Placed in the Public Domain.
3
4tid="scp3"
5
6#set -x
7
8COPY2=${OBJ}/copy2
9DIR=${COPY}.dd
10DIR2=${COPY}.dd2
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
23for mode in scp sftp ; do
24	scpopts="-F${OBJ}/ssh_proxy -S ${SSH} -q"
25	tag="$tid: $mode mode"
26	if test $mode = scp ; then
27		scpopts="$scpopts -O"
28	else
29		scpopts="-s -D ${SFTPSERVER}"
30	fi
31
32	verbose "$tag: simple copy remote file to remote file"
33	scpclean
34	$SCP $scpopts -3 hostA:${DATA} hostB:${COPY} || fail "copy failed"
35	cmp ${DATA} ${COPY} || fail "corrupted copy"
36
37	verbose "$tag: simple copy remote file to remote dir"
38	scpclean
39	cp ${DATA} ${COPY}
40	$SCP $scpopts -3 hostA:${COPY} hostB:${DIR} || fail "copy failed"
41	cmp ${COPY} ${DIR}/copy || fail "corrupted copy"
42
43	verbose "$tag: recursive remote dir to remote dir"
44	scpclean
45	rm -rf ${DIR2}
46	cp ${DATA} ${DIR}/copy
47	$SCP $scpopts -3r hostA:${DIR} hostB:${DIR2} || fail "copy failed"
48	diff -r ${DIR} ${DIR2} || fail "corrupted copy"
49	diff -r ${DIR2} ${DIR} || fail "corrupted copy"
50
51	verbose "$tag: detect non-directory target"
52	scpclean
53	echo a > ${COPY}
54	echo b > ${COPY2}
55	$SCP $scpopts -3 hostA:${DATA} hostA:${COPY} hostB:${COPY2}
56	cmp ${COPY} ${COPY2} >/dev/null && fail "corrupt target"
57done
58
59scpclean
60rm -f ${OBJ}/scp-ssh-wrapper.exe
61