wait a bit...

January 24, 2020

How to upload ephemeral files and text from your terminal to the cloud

This little script uploads an ephemeral (i.e. will be deleted after being accessed, aka. one-time-access) file or text (handy for passing out passwords) with custom expiry dates directly from your Linux terminal, using File.io’s API.

Time needed: 1 minute.

You can execute the script directly from the Github repo by using this handy trick:

  1. Run from your local terminal

    bash <(curl -Ls https://raw.githubusercontent.com/aorfanos/upload.sh/master/upload.sh) --{file,text} <PATH-TO-FILE | TEXT-IN-QUOTES> <EXPIRY-TIME>

  2. Receive a one-time link containing your attachment


  3. Visit the link

    Once the file/text is accessed once, it is removed from File.io and the link returns HTTP 404. This is ideal for quickly sharing text snippets, one-time passwords (better not any permanent or critical ones), backup archives and important documents securely, and with predefined custom expiration date, in order the recipient never opens the link.

The Script

#USAGE: upload --{file,text} <filename|plaintext> <expiry>       
# implement logging       
if [ ! -f $LOG_F ]       
 touch $LOG_F && chmod 644 $LOG_F       
exec 2>$LOG_F       
if [ $ACTION == "--file" ]       
 curl -sF "file=@$2" https://file.io/?expires=$EXPIRY | jq -r '.link'       
elif [ $ACTION == "--text" ]       
 curl -s --data "text=$2" https://file.io/?expires=$EXPIRY | jq -r '.link'       
 echo -en "Usage:\n\tupload --{file,text} <filename|plaintext> {expiry}\nDefaults:\n\tExpiry=1d\nExpiry options:\n\td(days)\n\tw(weeks)\n\tm(months)\n\ty(years)\n"       

The only thing we really need functionality-wise are the cURL commands enclosed in if, everything else is mainly to provide usability and a bit fault-tolerance to the script.

Posted in BashTaggs: