Skip to content

Instantly share code, notes, and snippets.

@kevn-xyz
Last active February 12, 2024 19:40
Show Gist options
  • Save kevn-xyz/c995ad626134c2cbfb79f0414a13ad45 to your computer and use it in GitHub Desktop.
Save kevn-xyz/c995ad626134c2cbfb79f0414a13ad45 to your computer and use it in GitHub Desktop.
Simple netcat based one shot http file server
#!/bin/bash
file=$1
port=$2
if [[ -n "$file" ]] && [[ -n "$port" ]]; then
{ echo -ne "HTTP/1.0 200 OK\r\nContent-Disposition: inline; filename=\"$1\"\r\nContent-Length: $(wc -c < $file)\r\n\r\n"; cat $file; } | nc -l $port
else
echo "Usage: ncws <file> <port>"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment