Make terminal upload file using file.io

- 3 mins

terminal

“The art of programming is the skill of controlling complexity.” – Marijn Haverbeke

One day I needed to send some confidential file without signup. I googled about such service available on the internet and found file.io.

According to file.io website -

Simply upload a file, share the link, and after it is downloaded, the file is completely deleted. For added security, set an expiration on the file and it is deleted within a certain amount of time, even if it was never downloaded. All files are encrypted when stored on our servers.

Most of my time goes into hitting commands on the terminal. file.io can be accessed using any browser but I wanted to take this functionality to the terminal. I browsed that website and found an easy to use API.

At first, I tried to add a command for uploading files using an alias but it didn’t work very fine. Then I thought of writing function which will be foolproof and give some errors for helping out the user if they type something wrong.

Before going ahead make sure you have curl installed. If you are using Ubuntu, do this -

sudo apt-get install curl

Add the functionality Automatically

Run this command in your terminal.

For bash

curl -L https://git.io/JeNX1 >> ~/.bashrc
source ~/.bashrc

For zsh

curl -L https://git.io/JeNX1 >> ~/.zshrc
source ~/.zshrc

Add the functionality Manually

Add this to your ~/.bashrc or ~/.zsh file and restart your terminal. I tested this on bash and zsh in Ubuntu 18.04 LTS.

# Upload file via terminal using file.io
# Author : Aman Roy (https://github.com/aman-roy)
upload () { if [ $# = 1 -o $# = 2 ];then if [ -f "$1" ];then if [ $# = 1 ];then curl -F "[email protected]$1" https://file.io/ ;else if [[ "$2" =~ ^[1-9]+[wmy]$ ]];then curl -F "[email protected]$1" https://file.io/\?expires=$2;else echo $'Wrong expiration format.\neg. 1(w/m/y), etc.';fi;fi;else echo "file doesn't exist";fi;else echo $'usage: upload file_name.ext [expiration]\nexpiration format: 1-9(w/m/y) # (w)eeks, m(onths), (y)ear';fi }

Usage

For simple file upload, do this

upload file.ext

I am assuming here that the file name is file.ext.

You can also set an expiration period. By default, the expiration is set to 14 days. Pass 3rd argument for expiration. You can write any positive number followed by w, m or y. w is for weeks, m for months and y for years.

upload file.ext 3w # Keeps the data on server for 21 days.
upload file.ext 2m # Keeps the data on server for 60 days.
upload file.ext 1y # Keeps the data on server for 365 days.

Conclusion

It is very useful when you have to send some small sensitive data to another person. You can be assured that the file you are sending to another person will be deleted after he/she download it. The only drawback is that you can’t send a large file(file_size < 100MB). Try this script on different shell out there and if you find any bug please let me know.

Aman Roy

Aman Roy

Geek, coder and pythonista!

comments powered by Disqus
rss facebook twitter github youtube mail spotify instagram linkedin google pinterest medium vimeo keybase stackoverflow reddit quora