This is a tutorial that teaches you how to create your own simple file-sharing service. It works in the terminal.
Usage:
$ share ~/pictures/my-funny-kitten.png
http://files.YOURDOMAIN.com/my-funny-kitten.png
after which you can paste the URL to a friend.
- A domain
- A VPS with a static public IP address running Linux
- A personal computer running Linux
- Nginx installed on the server
scp
andssh
on your personal computer- Your public SSH key added to authorized_keys on the server
- Free space :)
You'll need a directory in which the uploaded files will be stored:
mkdir /home/YOURUSER/uploaded-files
Replace YOURUSER
with the actual name of your user.
Create a new configuration file /etc/nginx/sites-available/file-uploads
with the following contents:
server {
listen 80;
server_name files.YOURDOMAIN.com;
access_log /var/log/nginx/files.YOURDOMAIN.com.access.log;
location / {
root /home/YOURUSER/uploaded-files;
}
}
After which you'll need to run service nginx restart
(or whatever is the equivalent in your OS.)
If you've done everything right, point your browser to http://files.YOURDOMAIN.com/ and you should get 403 Forbidden
A Bash script will be responsible for copying the file - over ssh - to the server. Create a script named upload.sh
with these contents:
#!/env/bash
ID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 8 | head -n 1)
scp $1 YOURUSER@YOURDOMAIN:/home/YOURUSER/uploaded-files/$ID-`basename $1`
echo "http://files.YOURDOMAIN.com/$ID-`basename $1`"
Make the script executable: chmod +x upload.sh
Then run: ./upload.sh ~/path/to/kitten-pic.png
and you should get a link in the console:
http://files.YOURDOMAIN.com/GF4afd3-kitten-pic.png
And there you go, your personal upload server.