File sharing is providing access to digital media such as computer programs and multimedia files such as music, images, videos e.t.c. It allows people to use similar files, being able to read, write, copy and modify them. In Linux, there are a couple file sharing options, among them are; Samba File sharing, NFS file sharing, SSH Linux file sharing, Transfer.sh file sharing e.t.c.

In this guide, we will discuss how to use Transfer.sh File sharing in Linux systems. Tranfers.sh is a free accommodation service that allows one upload files without need of an account up to a maximum of 10 GB. These files are then stored and available for 14 days after which they disappear.

Transfer.sh allows one to encrypt files with GPG before uploading. Also one can limit the maximum number of downloads and number of days the file will be available for sharing Transfer.sh has simplified the file sharing process as files are easily uploaded by running a shell function. These commands can also be run on windows systems by running Linux shell on them.

Upload a Single File Using cURL in Tranfer.sh

cURL (client URL) is used to transfer data to a server. This command makes it easy to share files in Tranfer.sh. To upload a file, open your terminal and run this command

$ curl --upload-file <path/file> https://transfer.sh

Running this command provides a URL on which the file has been uploaded. This is the sample output

$ curl --upload-file /home/rockylinux/il_340x270.2932224700_igpr.jpg https://transfer.sh
https://transfer.sh/1OP8lzQ/il_340x270.2932224700_igpr.jpg

When provided with a URL as above, you can share it with other people who you want to access this file. To access the file simply open the URL in a browser as below;

Upload Multiple files using Transfer.sh

With Transfer.sh, one can upload multiple files at the same time. This is achieved with the command:

$ curl -i -F [email protected]<path/file> -F [email protected]<path/file> https://transfer.sh/ 

Example:

$ curl -i -F [email protected]/root/IMG_20210426_200656_770.jpg -F [email protected]/root/croc.txt https://transfer.sh/ 
HTTP/2 200 
content-type: text/plain
server: Transfer.sh HTTP Server 1.0
x-made-with: <3 by DutchCoders
x-served-by: Proudly served by DutchCoders
content-length: 93
date: Wed, 23 Jun 2021 15:41:16 GMT

https://transfer.sh/1IRNRQk/IMG_20210426_200656_770.jpg
https://transfer.sh/1IRNRQk/croc.txt

Name an Upload File.

When using Tranfer.sh you can edit the initial command and add the name for your uploaded file as below;

$ curl --upload-file <path/file> https://transfer.sh/<file upload name>

Example:

$ curl --upload-file /home/rockylinux/il_340x270.2932224700_igpr.jpg https://transfer.sh/Jersey

In the above code, I have named the uploaded file as Jersey. opening the provided URL in a browser allows you to download a file named Jersey instead of the original file’s name.

Sample output;

Set the Maximum Number of Downloads and Days a File is Downloadable.

With Transfer.sh as stated earlier, you can set the maximum number of downloads and maximum number of days your upload file is available for downloading. This is achieved by adding an extension to our initial cURL command like this:

$ curl -H "Max-Downloads: 1" -H "Max-Days: 2" --upload-file /root/IMG_20210426_200656_770.jpg https://transfer.sh/jersey
https://transfer.sh/1tii4Eu/jersey

With the above command, there are two set headers, the maximum number of downloads which is 1 and the maximum number of days the file is available for downloading which is 2. You can edit these figures to match your desired maximum downloads and number of days the file can be downloaded.

Encrypt and Upload files Using GPG

For security reasons, this application allows one to encrypt files before uploading. This is achieved by running this command

$ cat root/Jersey.jpg |gpg -ac -o-|curl -X PUT --upload-file "-" https://transfer.sh/Jersey

Example:

$ cat /root/IMG_20210426_200656_770.jpg |gpg -ac -o-|curl -X PUT --upload-file "-" https://transfer.sh/Jersey
https://transfer.sh/1H1wAZ5/Jersey

When you run the above command, you are required to set a passphrase used to encrypt your files.

Configure GPG.

In instances where GPG doesn’t work, outputs this error. Ignore this step if GPG works well for you.

gpg: problem with the agent: Inappropriate ioctl for device
gpg: error creating passphrase: Operation cancelled
gpg: symmetric encryption of '[stdin]' failed: Operation cancelled

This error occurs because GnuPG ignores the passphrases received through stdin. You are required to make the following settings:

Enable loopback pinetry mode by adding this to ~/.gnupg/gpg.conf

use-agent 
pinentry-mode loopback

Create ~/.gnupg/gpg-agent.conf if this file is not available and add this line

allow-loopback-pinentry

Then restart the agent by running:

$ sudo echo RELOADAGENT | gpg-connect-agent

With this,you are good to go, you can now encrypt and decrypt your shared files.

Depcrypt shared Files with GPG

To download and decrypt the shared file above run this command:

$ curl https://transfer.sh/1nnAeWZ/Jersey | gpg -o- > ./Jersey

The above command gives this output

$ curl https://transfer.sh/1nnAeWZ/Jersey | gpg -o- > ./Jersey
gpg: WARNING: no command supplied.  Trying to guess what you mean ...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0 52809    0     0    0     0      0      0 --:--:--  0:00:01 --:--:--     0gpg: AES256 encrypted data
100 52809  100 52809    0     0  38462      0  0:00:01  0:00:01 --:--:-- 38462
gpg: encrypted with 1 passphrase

Use Shell Function In Trasfer.sh

Creating an alias command helps to create a shorter command to be used in file sharing. This is achieved by adding an alias to .zshrc or .bashrc using:

$ sudo vi ~/.bashrc
or
$ sudo vi ~/.zshrc

To this file, only add to one tool of interest, either cURL or wget. In the below lines, I have added the alias to cURL

##using curl
transfer() {
    curl --progress-bar --upload-file "$1" https://transfer.sh/$(basename $1) | tee /dev/null;
}

alias transfer=transfer
##using wget
transfer() {
    wget -t 1 -qO - --method=PUT --body-file="$1" --header="Content-Type: $(file -b --mime-type $1)" https://transfer.sh/$(basename $1);
}

alias transfer=transfer

After saving the file,use these commands to apply changes

$ source ~/.bashrc
OR
$ source ~/.zshrc

With applied changes, we now have a shorter transfer command as;

$ transfer /root/IMG_20210426_200656_770.jpg

Conclusion

From the above demonstration, Transfer.sh has proven to solve data sharing problem between users. One can be able to transfer files to other computers, mobile devices, encrypt data and set other parameters such as maximum downloads and number of days files are available.

I hope this article was of help to you. View other related articles.

Securely Transfer Files and Folders between Two computers using Croc

Transfer files over WiFi from computer to mobile device by scanning a QR code

LEAVE A REPLY

Please enter your comment!
Please enter your name here