xref: /freebsd/crypto/openssh/regress/scp3.sh (revision 2fb4f839f3fc72ce2bab12f9ba4760f97f73e97f)
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
12$SSH -F $OBJ/ssh_proxy somehost \
13    'IFS=":"; for i in $PATH;do [ -x "$i/scp" ] && exit 0; done; exit 1'
14if [ $? -eq 1 ]; then
15	skip "No scp on remote path."
16fi
17
18SRC=`dirname ${SCRIPT}`
19cp ${SRC}/scp-ssh-wrapper.sh ${OBJ}/scp-ssh-wrapper.scp
20chmod 755 ${OBJ}/scp-ssh-wrapper.scp
21export SCP # used in scp-ssh-wrapper.scp
22
23scpclean() {
24	rm -rf ${COPY} ${COPY2} ${DIR} ${DIR2}
25	mkdir ${DIR} ${DIR2}
26	chmod 755 ${DIR} ${DIR2}
27}
28
29for mode in scp sftp ; do
30	scpopts="-F${OBJ}/ssh_proxy -S ${SSH} -q"
31	tag="$tid: $mode mode"
32	if test $mode = scp ; then
33		scpopts="$scpopts -O"
34	else
35		scpopts="-s -D ${SFTPSERVER}"
36	fi
37
38	verbose "$tag: simple copy remote file to remote file"
39	scpclean
40	$SCP $scpopts -3 hostA:${DATA} hostB:${COPY} || fail "copy failed"
41	cmp ${DATA} ${COPY} || fail "corrupted copy"
42
43	verbose "$tag: simple copy remote file to remote dir"
44	scpclean
45	cp ${DATA} ${COPY}
46	$SCP $scpopts -3 hostA:${COPY} hostB:${DIR} || fail "copy failed"
47	cmp ${COPY} ${DIR}/copy || fail "corrupted copy"
48
49	verbose "$tag: recursive remote dir to remote dir"
50	scpclean
51	rm -rf ${DIR2}
52	cp ${DATA} ${DIR}/copy
53	$SCP $scpopts -3r hostA:${DIR} hostB:${DIR2} || fail "copy failed"
54	diff -r ${DIR} ${DIR2} || fail "corrupted copy"
55	diff -r ${DIR2} ${DIR} || fail "corrupted copy"
56
57	verbose "$tag: detect non-directory target"
58	scpclean
59	echo a > ${COPY}
60	echo b > ${COPY2}
61	$SCP $scpopts -3 hostA:${DATA} hostA:${COPY} hostB:${COPY2}
62	cmp ${COPY} ${COPY2} >/dev/null && fail "corrupt target"
63done
64
65scpclean
66rm -f ${OBJ}/scp-ssh-wrapper.exe
67