summaryrefslogtreecommitdiff
path: root/regress/usr.bin/ftp/redirect.sh
blob: 7432b1e1e3a82404427c5799f9fdfd1b060b78e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/sh
#	$OpenBSD: redirect.sh,v 1.5 2017/01/23 22:26:19 bluhm Exp $

: ${FTP:=ftp}

: ${rport1:=9000}
: ${rport2:=9001}

req1=$1
loc=$2
req2=$3

echo "Testing $req1 => $loc => $req2"

# Be sure to kill any previous nc running on our port
while pkill -fx "nc -4 -l $rport1" && sleep 1; do done

echo "HTTP/1.0 302 Found\r\nLocation: $loc\r\n\r" | \
     nc -4 -l $rport1 >/dev/null &

# Wait for the "server" to start
until fstat | egrep 'nc[ ]+.*tcp 0x[0-9a-f]* \*:9000' > /dev/null; do
	sleep .1
done

unset ftp_proxy

res=$(${FTP} -4 -o/dev/null -v $req1 2>&1 | \
    sed '/^Redirected to /{s///;x;};$!d;x')

if [ X"$res" != X"$req2" ]; then
	echo "*** Fail; expected \"$req2\", got \"$res\""
	exit 1
fi