DEV Community

Ben Adrian Sarmiento
Ben Adrian Sarmiento

Posted on

A free personal file host on your command line

I'm a big fan of file sharing, but not through cloud storage solutions like Google Drive and Dropbox. There's so much bloat on their UIs that sways from the intent of just sharing a file to someone. I thought of managing my own FTP server but paying something monthly for the few occasions I'm going to share a file doesn't sound like a good idea.

Then came IBM cloud and their free offerings. The coolest thing about IBM cloud is they don't ask your credit card details to avail the free stuff. Plus their free tier is actually generous. Check Cloud Object Storage as an example:

Alt Text

That's 5GB of public outbound traffic. If I go only with sharing screenshots, that's a lot of screenshots I'll be able to share. And IBM COS is what I actually use as my file host. If you check the URL of the image above, it uses my domain files.bensarmiento.com which is just a CNAME a configured to point to my COS bucket. (OK, so apparently it isn't as everything goes through dev.to's image CDN which is Cloudinary)

Now to do the file host you need the following: IBM COS bucket, service credentials (you can setup this one when creating the bucket), and rclone installed on your local machine. rclone is a nifty tool for anything cloud storage, I suggest checking it out.

After setting up the bucket, if you want a subdomain to not expose the ugly IBM COS domain on the URL you can do that by adding a CNAME record with value s3.<region code>.cloud-object-storage.appdomain.cloud.

Next step is to configure rclone to upload to it. Easiest way to is to edit rclone.conf found in $HOME/.config/rclone/.

This should be what's inside (replace everything <that looks like this>):

[ibm]
type = s3
provider = IBMCOS
env_auth = false
access_key_id = <access key>
secret_access_key = <secret key>
region = <region code>
endpoint = s3.<region code>.cloud-object-storage.appdomain.cloud
acl = public-read

After that, the command rclone copy local.file ibm:<bucket-name> should work. Then in your .bashrc or .zshrc:

function upload {
    rclone copy $1 ibm:<bucket-name>
    a=`basename $1`
    b=`echo $a | urlenc enc`
    echo "https://<your configured url>/<bucket-name>/$b"
}

So now, you should be able to do upload local.file which will output you something like https://files.bensarmiento.com/ben-files/Screenshot%202020-02-02%20at%204.15.32%20PM.png.

Bonus: you can setup something like a URL shortener of some sort with this setup (if your bucket URL is short).

function redirect {
    a=`mktemp /tmp/goto.XXXXXXXX`
    b=`echo "$a.html"`
    echo "<meta http-equiv='Refresh' content='1; url=$1'>Redirecting to $1..." > $b
    upload $b
}

Hope other providers can offer more generous free tiers.

Top comments (0)