How to Upload and Share Files From the Terminal Using Transfer.sh

Generally, file sharing involves logging into a storage provider, manually locating the file, and uploading it via the graphical user interface of a web browser or application. While the time wasted during these intermediate steps may not seem like much, it keeps on adding up every time you wish to upload or share a file.

But sharing files doesn’t have to be tedious anymore. With the Linux terminal, you can do this in a jiffy. Thanks to tools like transfer.sh, all it takes is a simple command on your terminal to upload a file.

What Is Transfer.sh?

Transfer.sh is a free platform that enables easy and fast file sharing via the Linux shell. Uploading a file is as simple as running a cURL command or a shell function with the file you want to upload as the parameter. You can also use these commands on Windows 10 by running a Linux bash shell on it.

Learn More: How to Get the Linux Bash Shell on Windows 10

Here are some significant features that transfer.sh offers:

  • Requires no GUI, uses the command line.
  • Upload files with sizes up to 10GB.
  • Files are only stored for 14 days.
  • Optionally encrypt the files with GPG before transfer.
  • Limit the number of downloads and days for which the file will be available.

Uploading a File via cURL

Client URL (cURL) is a command-line tool used for transferring data to and from a server, using various network protocols. Uploading a file via cURL and transfer.sh is a straightforward process. All you have to do is open up your Linux terminal and use the following syntax to upload a file:

curl --upload-file  https://transfer.sh

In the above command, make sure to replace  with the actual path of the file you want to upload.

On running the command, you’ll get a URL that you can share with other people for them to download your uploaded file.

You can tweak the above command to change the name and extension of the uploaded file in this manner:

curl --upload-file  https://transfer.sh/

In the above example, cURL renamed the file hello.txt to test.md before uploading. On visiting the download link, you’ll be prompted to download the test.md file instead of the original file.

Moreover, you can even set the maximum number of downloads allowed and the maximum number of days for which the file will be downloadable by adding some headers to the cURL command. Here’s an example that illustrates this feature:

Here, the cURL command consists of 2 HTTP headers: Max-Downloads and Max-Days. You can change the value after the colons as per your requirements.

Uploading via Shell Function

Although the cURL command is pretty simple, you can take it a step further and make it even easier by creating a shell function. You can then use this shell function to substitute the whole cURL command with a single word.

To get started, navigate to the /home directory on your Linux machine and open the .bashrc or .zshrc file depending on the shell you use. Feel free to use any Linux text editor of your preference. Paste the shell function given below to the end of the file and save it once done.

transfer(){ if [ $# -eq 0 ];then echo "No arguments specified.
Usage:
transfer
... | transfer ">&2;return 1;fi;if tty -s;then file="$1";file_name=$(basename "$file");if [ ! -e "$file" ];then echo "$file: No such file or directory">&2;return 1;fi;if [ -d "$file" ];then file_name="$file_name.zip" ,;(cd "$file"&&zip -r -q - .)|curl --progress-bar --upload-file "-" "https://transfer.sh/$file_name"|tee /dev/null,;else cat "$file"|curl --progress-bar --upload-file "-" "https://transfer.sh/$file_name"|tee /dev/null;fi;else file_name=$1;curl --progress-bar --upload-file "-" "https://transfer.sh/$file_name"|tee /dev/null;fi;}

For the shell function to work, you will have to close the existing terminal instances and start a new one. Alternatively, you can run source ~/.bashrc if you use the bash shell, or source ~/.zshrc if you use the Z shell. Now, you can upload files using the transfer command from your Linux terminal.

Related: How to Change the Default Shell on Linux With chsh

File Sharing Made Easy on Linux

While transfer.sh is a great utility for obtaining a sharable download URL for your files, it isn’t an alternative for replacing your cloud storage entirely. It is exceptional for sharing your files temporarily as it only stores your files for 14 days maximum.

For longer-lasting personal storage, you can lean towards cloud storage providers. Don’t worry. Many cloud service providers offer a free tier that you can use to decide whether you want to make the purchase.

Source: makeuseof.com

Related posts

Connections #329: Today’s Answer and Clues (Sunday, May 5, 2024)

PC Fans Running at Full Throttle? 6 Fixes

The 5 Best Free Driver Updaters for Windows