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

    https://file.io/5P0qgB

  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

#!/bin/bash       
                
       
                
#USAGE: upload --{file,text} <filename|plaintext> <expiry>       
                
       
                
# implement logging       
                
LOG_F="/tmp/f-upload.err"       
                
if [ ! -f $LOG_F ]       
                
then       
                
 touch $LOG_F && chmod 644 $LOG_F       
                
fi       
                
       
                
exec 2>$LOG_F       
                
       
                
ACTION=${1}       
                
EXPIRY=${3:-1d}       
                
       
                
if [ $ACTION == "--file" ]       
                
then       
                
 curl -sF "file=@$2" https://file.io/?expires=$EXPIRY | jq -r '.link'       
                
elif [ $ACTION == "--text" ]       
                
then       
                
 curl -s --data "text=$2" https://file.io/?expires=$EXPIRY | jq -r '.link'       
                
else       
                
 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"       
                
fi

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: