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