Sending Data Without Hassle
At some point in time we all have been in a situation where we had to send some data to someone but we couldn’t figure out what’s the best way to send it. Emailing works… for file sizes upto 25 MB. You can put the file into a cloud storage platform like Google Drive or Dropbox, and ask the other person to download it from there. But that is quite inefficient if you just want to share the data with one person. Since we are all working from home, this usecase has become pretty frequent
I too found this issue annoying. The biggest problem I faced was for really big files, I had to upload the file first and then only the other person could download it. This was because the whole flow was sequential.
Recently I came across a very awesome open source project croc. It is a cli tool, built using golang, that provides following features:-
- allows any two computers to transfer data (using a relay)
- provides end-to-end encryption (using PAKE)
- enables easy cross-platform transfers (Windows, Linux, Mac)
- allows multiple file transfers
- allows resuming transfers that are interrupted
- local server or port-forwarding not needed
- ipv6-first with ipv4 fallback
- can use proxy, like tor
It is really a very straightforward tool to use and very useful for following reasons:-
Available for everyone
It is widely supported, can easily install it from package manager of your OS. Since it’s open source, it can be built from source, given go is already installed.
Parallelizing download and upload
The key advantage of croc is it’s ability to make the sequential flow of upload download into a concurrent one. It uses a relay server to establish commnication then take the stream of data as input and sends it to the output at the same time. So the speed of transfer is limited only by individual’s bandwidth. This is a very efficient and secure way of sending data. Since the server is just a relay server it doesn’t require any maintenance as it just acts as a buffer to upload and download files. The concept is simple yet brilliant.
Sending a file is dead simple
It is really easy to use for sending files and folders.
$ croc send [file(s) or folder]
Once you execute this command you’ll get a response like this
Code is: some-specific-code
On the other computer runcroc some-specific-code
Following the instructions just run the command on reciever’s machine and voilla it will ask for confirmation and your file transfer will begin.
A bit about security
It uses PAKE (password authenticated key exchange) for secure data transfer. It is much safer than passwords and no one needs to make an account 😛
A little customisation
To save the hassle of depending on the code being generated you can provide your own super secret code.
$ croc send --code secret-code file
Now you’ll know what is the exact code that needs to be entered to receive the file at recipient’s end.
Now for the interesting part
It allows user to pipe stdout data and send it, and on reciever’s side it can be used as stdin. This blew my mind, not gonna lie.
Send the file using:-
$ cat hello.txt | croc send --code secret-code
And on reciever’s side:-
$ croc --yes secret-code
Or if you want to save it to file
$ croc --yes secret-code > out
The possibilities are really endless with this one. Technically I can provide input to program on another computer or print the output of some other program without starting any server on any of the machines.
Also simple text can be sent to stdout of receiver as well
$ croc send --code secret-code --text "Hello World"
Proxy
If you have a forward proxy server running, you can use that to connect with relay server instead.
$ croc --socks5 "127.0.0.1:9050" send SOMEFILE
Self-host relay
By default croc uses a public relay server that handles the parallel upload and download. The cli program can act as a relay as well. Install croc on the server you want use as relay and run
$ croc relay
By default croc uses ports 9009–9013. But you can use your own ports:-
$ croc relay --ports 8000,8001
Note that relay must be provided with atleast 2 ports to relay server, as it uses first port for communication and subsequent ports for multiplexed data transfer. So the more ports provided, the merrier it is.
To send files using the self hosted relay:-
$ croc --relay "myrelay.example.com:9009" send [filename]
For easier setup, docker can be used to get the relay server up and running
$ docker run -d -p 9009-9013:9009-9013 -e CROC_PASS='YOURPASSWORD' schollz/croc
CROC_PASS='YOURPASSWORD'
secures your relay server with a password. Only send requests with this password will be able to send the file.
$ croc --pass YOURPASSWORD --relay "myrelay.example.com:9009" send [filename]
Password can be kept in a file and supplied to this command instead of entering the text.