8

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

 3 years ago
source link: https://www.makeuseof.com/upload-and-share-files-from-terminal-using-transfer-sh/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

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

By Nitin Ranganath

Published 1 hour ago

Want to speed up the process of uploading and sharing files on Linux? Here's how to use Transfer.sh from the command line.

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 <path-to-file> https://transfer.sh

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

Uploading a file via transfer.sh

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

transfer.sh download page

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

curl --upload-file <path-to-file> https://transfer.sh/<file_name.extension>
Uploading a file with different name and extension

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:

transfer.sh limiting downloads and days

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 <file|directory>
... | transfer <file_name>">&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.

Shell function for transfer.sh

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.

About The Author

607961b40c2b9-me.png?fit=crop&w=100&h=100

Nitin Ranganath (17 Articles Published)

Nitin is an avid software developer and a computer engineering student developing web applications using JavaScript technologies. He works as a freelance web developer and likes to write for Linux and Programming in his free time.

More From Nitin Ranganath

Subscribe To Our Newsletter

Join our newsletter for tech tips, reviews, free ebooks, and exclusive deals!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK