What is this?
This is not supposed to be a tutorial and a basic knowledge about Linux is assumed.
If I have this movie I want to watch when I get home, I will have to wait till I am home then download the movie and then watch it. With the kind of internet I have, the download may take around 1-2 hours. I am an impatient person and I can’t wait that long. So I took some bits and pieces that I knew and set up my personal download box which runs as long as internet and electricity is provided to it.
(This is not a dedicated server for a live site, so I don’t have a guaranteed uptime of 99.99% 😀 ).
How did I do it?
I had a Raspberry Pi 2 lying around that I wanted to put to good use. I got a Ethernet cable and connected it to my router and set it up. I was able to SSH into it (a good start). I installed aria2c on it.
To be able to download a single file or a few files(locally, from my home) this is perfect.
aria2c -x10 "https://www.example.com/movie.mp4"
aria2c -x10 -i list_of_movies.txt
with list_of_movies.txt containing multiple URL each in its own separate line. Cool till now? This ain’t no rocket science. Then I came to the point where I wanted to be able to do this remotely, maybe I’m out with my friends or somewhere and I decide I want to watch this movie X. I want to get a download link for X and put it on my download box to keep it downloaded for when I reach home. Now these commands become meaningless if I’m not able to SSH into my rPi and run these commands.
So I read up more on a topic I had known about, that is Reverse SSH tunneling. You can get the idea from here – How does reverse SSH tunneling work? I have a droplet running on DigitalOcean. I set up my key based authentication for SSH and set up a reverse SSH Tunnel using
ssh -f -N -T -R686868:localhost:22 firstname.lastname@example.org
Now the problem was, although this reverse tunnel worked perfectly, it will definitely close down on power loss or maybe connectivity loss. I could put this up in cron or write a script which ran this command periodically. Instead I found something that does a pretty awesome job of maintaining a persistent reverse SSH tunnel.
autossh -M 10994 -q -N -o "PubkeyAuthentication=yes" -o "PasswordAuthentication=no" -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -R 6666:localhost:22 email@example.com -p 2212 &
Now a persistent connection exists always between the rPi and my remote droplet. Now I can SSH anytime and add a download link to aria2c which I run in daemon mode.
aria2c --enable-rpc --rpc-listen-all --rpc-secret mysecret
Then to add a download link, I do
aria2rpc addUri "https://www.example.com/movie.mp4" -x10
For aria2rpc look at – aria2rpc. This is not perfect, maybe an Android app(which might exist) or a web interface would be nice. 🙂
P.S. – A web interface does exist, but I haven’t tinkered with it. WebUI Aria2