Curl Hot to Upload a File From Mac Terminal
Generally, file sharing involves logging into a storage provider, manually locating the file, and uploading it via the graphical user interface of a spider web browser or application. While the fourth dimension wasted during these intermediate steps may not seem like much, information technology keeps on adding up every time you wish to upload or share a file.
But sharing files doesn't have to exist tedious anymore. With the Linux concluding, you can do this in a jiffy. Thanks to tools liketransfer.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 uncomplicated as running a whorl command or a beat function with the file y'all want to upload as the parameter. You lot can likewise use these commands on Windows 10 by running a Linux bash beat on it.
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
Customer 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 procedure. All yous take to do is open up up your Linux terminal and utilize the following syntax to upload a file:
scroll --upload-file <path-to-file> https://transfer.sh
In the above control, make sure to replace<path-to-file>with the bodily path of the file you lot desire to upload.
On running the command, yous'll go a URL that you can share with other people for them to download your uploaded file.
Y'all tin can tweak the above control 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>
In the above example, coil renamed the filehello.txt totest.md before uploading. On visiting the download link, you'll be prompted to download thetest.medico file instead of the original file.
Moreover, you lot can even set the maximum number of downloads allowed and the maximum number of days for which the file will exist downloadable by adding some headers to the cURL command. Here'due south an example that illustrates this characteristic:
Here, the gyre command consists of 2 HTTP headers:Max-Downloads andMax-Days. You tin change the value after the colons every bit per your requirements.
Uploading via Crush Role
Although the cURL command is pretty unproblematic, you can take information technology a step further and make it fifty-fifty easier past creating a crush function. You can then use this beat function to substitute the whole scroll command with a unmarried give-and-take.
To go started, navigate to the /abode directory on your Linux machine and open the.bashrcor.zshrc file depending on the shell y'all use. Experience free to use whatsoever Linux text editor of your preference. Paste the beat out function given below to the end of the file and save information technology once done.
transfer(){ if [ $# -eq 0 ];and so echo "No arguments specified.
Usage:
transfer <file|directory>
... | transfer <file_name>">ⅈreturn 1;fi;if tty -s;so file="$1";file_name=$(basename "$file");if [ ! -e "$file" ];so echo "$file: No such file or directory">ⅈreturn 1;fi;if [ -d "$file" ];and then file_name="$file_name.zip" ,;(cd "$file"&&naught -r -q - .)|curl --progress-bar --upload-file "-" "https://transfer.sh/$file_name"|tee /dev/nil,;else true cat "$file"|roll --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 lot will have to shut the existing terminal instances and beginning a new 1. Alternatively, y'all can runsource ~/.bashrc if you apply the bash vanquish, orsource ~/.zshrc if you apply the Z shell. At present, you lot can upload files using thetransfer command from your Linux terminal.
File Sharing Made Piece of cake on Linux
While transfer.sh is a swell utility for obtaining a sharable download URL for your files, it isn't an alternative for replacing your deject storage entirely. It is exceptional for sharing your files temporarily as it merely stores your files for xiv days maximum.
For longer-lasting personal storage, y'all can lean towards deject storage providers. Don't worry. Many cloud service providers offer a free tier that you can use to determine whether yous want to brand the purchase.
About The Author
Source: https://www.makeuseof.com/upload-and-share-files-from-terminal-using-transfer-sh/
0 Response to "Curl Hot to Upload a File From Mac Terminal"
Post a Comment