Skip to content

Instantly share code, notes, and snippets.

@agustik
Created April 10, 2024 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agustik/5db8ce0807a0764bafd6882c09db0084 to your computer and use it in GitHub Desktop.
Save agustik/5db8ce0807a0764bafd6882c09db0084 to your computer and use it in GitHub Desktop.
#!/bin/bash
port=$(shuf -i 9000-60000 -n 1)
file=$1
if [[ -z "$1" ]]; then
echo "Missing file, use $0 <file>"
exit 1
fi
md5=$(md5sum $file | awk '{ print $1 }')
name=$(basename "$file")
primaryip=$(ip route get 1.1.1.1 | grep -oP 'src \K\S+')
echo "Serving file on $port
# To fetch the file use:
# curl http://$HOSTNAME:$port -o $name
# Or using ip
# curl http://$primaryip:$port -o $name
#
# Check the content, md5sum $name it should be:
# $md5
# Hint, you might need to turn of your firewall
# sudo systecmtl stop iptables
# "
cat <(echo "HTTP/1.1 200 OK
Content-Type: Content-type: application/octet-stream
E-Tag: $md5
Content-Disposition: attachment; filename=\"$name\"
Content-Length: $( du -b $file )
Server: Netcat
" ) $file | nc -l $port > /dev/null
echo "Transfer complete"
@agustik
Copy link
Author

agustik commented Apr 10, 2024

Simple http server to transfer files between linux servers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment