aboutsummaryrefslogtreecommitdiff
path: root/sem7/dist/lec1/exc1.bash
blob: e777f172bd52bfd562b5ad6d0352d568f9beb080 (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
#!/usr/bin/env bash
set -e

if [ "$#" -lt 2 ]; then
    echo Not enough arguments, use $0 inputfile outputfile
    exit 1
fi

inputfile=$1

if [[ ! -f "$inputfile" ]]; then
    echo File $inputfile does not exist
    exit 1
fi

outputfile=$2

echo Sending file $inputfile into $outputfile

# Open a server
nc -l -p 8080 > $outputfile &

# Connect with client and send file
nc -c 127.0.0.1 8080 < $inputfile

echo Done