Send People your Files

January 11, 2014

So you have a large file. You want to send it to someone. You can use Netcat!

#!/bin/bash
{ echo -ne "HTTP/1.0 200 OK\r\nContent-Type: $(file -b --mime-type "$2")\r\nContent-Length: $(stat -c%s "$2")\r\n\r\n"; cat "$2"; } | nc -l "$1"

This script is based on wikipedia’s netcat example. It is updated to include some information which allows streaming videos (VLC wants a file type and length).

To make the file ‘file.mp4’ available on port 1080, you run the bash script:

./fileserver 1080 file.mp4

Once your friend downloads it, the script returns - it only makes the file available once.

When you run the script, all the other person needs to do is point their web browser (or VLC/mplayer) at your ip and port number.