Last active
August 29, 2015 14:15
-
-
Save markstos/93022b61bd49a0fbb045 to your computer and use it in GitHub Desktop.
oneshot - a single-use, single-file web server to serve a file and then shutdown. Share a file directly with a network neighbor-- no third-party needed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
USAGE="Usage: $0 file.txt. Start a webserver on port $PORT, serve this file and close the connection."; | |
# exit if there's an error | |
set -e | |
HOSTNAME=`hostname -I | cut -d' ' -f1`; | |
PORT=8000 | |
if [ "$#" == "0" ]; then | |
echo "$USAGE" | |
exit 1 | |
fi | |
FILE=$1; | |
echo "Serving $FILE one time at http://$HOSTNAME:$PORT"; | |
{ echo -ne "HTTP/1.0 200 OK\r\nContent-Disposition: attachment;filename="`basename $FILE`"\r\nContent-Length: $(wc -c <$FILE)\r\n\r\n"; cat $FILE; } | nc -l $PORT | |
# Potential features: | |
# * Random open port selection | |
# * SSL support (with "sslnetcat", "scnc", or ncat ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For personal use it only. Note it calls the shell with unsanitized input. Only use with your filenames that you provide and trust.