Skip to content

Instantly share code, notes, and snippets.

@hughpearse
Forked from kevn-xyz/ncws
Created January 21, 2019 14:25
Show Gist options
  • Save hughpearse/6696f62cb94dacf2cdfc97cc84d1753e to your computer and use it in GitHub Desktop.
Save hughpearse/6696f62cb94dacf2cdfc97cc84d1753e 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\nContent-Type: application/octet-stream\nContent-Disposition: inline; filename=\"$1\"\nContent-Length: $(wc -c < $file)\n\n"; cat $file; } | nc -l $port
else
echo "Usage: $(basename $0) <file> <port>"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment