Skip to content

Instantly share code, notes, and snippets.

@amadoalmex
Forked from talwai/servefile.sh
Last active October 25, 2020 00:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save amadoalmex/d967504d6b1434675fdf05639e6d3ffb to your computer and use it in GitHub Desktop.
Save amadoalmex/d967504d6b1434675fdf05639e6d3ffb to your computer and use it in GitHub Desktop.
One-shot HTTP webserver to serve file contents using netcat
serveit(){
clen=$(wc -c < "$1" | cut -f1 -d' ')
while true ; do
cat <<endheaders
HTTP/1.0 200 OK
Content-Type: application/octet-stream
Content-Length: $clen
Content-Disposition: attachment; filename="$1"
endheaders
cat "$1"
break;
done | nc -l -p 8789 ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment