xref: /freebsd/crypto/openssh/regress/scp-uri.sh (revision 3332f1b444d4a73238e9f59cca27bfc95fe936bd)
1#	$OpenBSD: scp-uri.sh,v 1.4 2021/08/10 03:35:45 djm 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
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}
21
22# Remove Port and User from ssh_config, we want to rely on the URI
23cp $OBJ/ssh_config $OBJ/ssh_config.orig
24egrep -v '^	+(Port|User)	+.*$' $OBJ/ssh_config.orig > $OBJ/ssh_config
25
26for mode in scp sftp ; do
27	tag="$tid: $mode mode"
28	if test $mode = scp ; then
29		scpopts="-O -q -S ${OBJ}/scp-ssh-wrapper.scp"
30	else
31		scpopts="-s -D ${SFTPSERVER}"
32	fi
33	verbose "$tag: simple copy local file to remote file"
34	scpclean
35	$SCP $scpopts ${DATA} "scp://${USER}@somehost:${PORT}/${COPY}" || fail "copy failed"
36	cmp ${DATA} ${COPY} || fail "corrupted copy"
37
38	verbose "$tag: simple copy remote file to local file"
39	scpclean
40	$SCP $scpopts "scp://${USER}@somehost:${PORT}/${DATA}" ${COPY} || fail "copy failed"
41	cmp ${DATA} ${COPY} || fail "corrupted copy"
42
43	verbose "$tag: simple copy local file to remote dir"
44	scpclean
45	cp ${DATA} ${COPY}
46	$SCP $scpopts ${COPY} "scp://${USER}@somehost:${PORT}/${DIR}" || fail "copy failed"
47	cmp ${COPY} ${DIR}/copy || fail "corrupted copy"
48
49	verbose "$tag: simple copy remote file to local dir"
50	scpclean
51	cp ${DATA} ${COPY}
52	$SCP $scpopts "scp://${USER}@somehost:${PORT}/${COPY}" ${DIR} || fail "copy failed"
53	cmp ${COPY} ${DIR}/copy || fail "corrupted copy"
54
55	verbose "$tag: recursive local dir to remote dir"
56	scpclean
57	rm -rf ${DIR2}
58	cp ${DATA} ${DIR}/copy
59	$SCP $scpopts -r ${DIR} "scp://${USER}@somehost:${PORT}/${DIR2}" || fail "copy failed"
60	for i in $(cd ${DIR} && echo *); do
61		cmp ${DIR}/$i ${DIR2}/$i || fail "corrupted copy"
62	done
63
64	verbose "$tag: recursive remote dir to local dir"
65	scpclean
66	rm -rf ${DIR2}
67	cp ${DATA} ${DIR}/copy
68	$SCP $scpopts -r "scp://${USER}@somehost:${PORT}/${DIR}" ${DIR2} || fail "copy failed"
69	for i in $(cd ${DIR} && echo *); do
70		cmp ${DIR}/$i ${DIR2}/$i || fail "corrupted copy"
71	done
72
73	# TODO: scp -3
74done
75
76scpclean
77rm -f ${OBJ}/scp-ssh-wrapper.exe
78