banner



How Do I Upload A File Via Terminal

Make terminal upload file using file.io

terminal

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

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

Co-ordinate to file.io website -

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

Most of my time goes into striking commands on the terminal. file.io tin be accessed using any browser merely 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.

Earlier going ahead make certain you take curl installed. If you lot are using Ubuntu, do this -

                          sudo              apt-get              install              coil          

Add the functionality Automatically

Run this control in your terminal.

For bash

            curl              -Fifty              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 eighteen.04 LTS .

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

Usage

For simple file upload, practise this

            upload file.ext          

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

You tin also fix an expiration period. By default, the expiration is set up to 14 days. Pass 3rd argument for expiration. Y'all tin can write whatsoever positive number followed past west, m or y. w is for weeks, one thousand for months and y for years.

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

Determination

It is very useful when you have to transport some small sensitive data to some other person. Y'all can be bodacious that the file you lot are sending to some other person will exist deleted after he/she download it. The merely drawback is that you lot can't ship a large file(file_size < 100MB). Try this script on different beat out there and if you discover any bug delight let me know.



Source: http://amanroy.me/upload-file-from-terminal

Posted by: walleronvalcor.blogspot.com

0 Response to "How Do I Upload A File Via Terminal"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel