Raspberry Pi as Download Server
I take IoT course this semester. This is a small, but practical project on Raspberry Pi. The idea is from cloud storage transferring. I want to move all files from Baidu Wangpan to Google drive because of many limitation of Baidu. Finally, I deploy several enhancement functions on Raspberry:
- Download, such as HTTP/HTTPS, FTP, SFTP, BitTorrent and Metalink (Aria2)
- Domian name (Dynu.net)
- Backup to cloud storage, such as Google Drive (Rclone)
- Auto upload script
- Optional: Baidu Wanpan client (Baidupcs-web)
1. Download function: Aria2 and AriaNg
Aria2 is a lightweight multi-protocol & multi-source command-line download utility.
AriaNg is a modern web frontend making aria2 easier to use. You can just put AriaNg in your web server and open it in your browser.
- Install Aria2
sudo apt-get install aria2
Aria2 should run with configuration file. You can find configuration file from official website. Or use my configuration file
cd ~
wget https://github.com/YifangY/IoTProject2019/blob/master/aria2.conf
Please modify line 2, 3, 4, 8
Create session file:
mkdir /home/pi/.aria2/
touch /home/pi/.aria2/aria2.session
Aria2 can start by the command:
aria2c --conf-path={aria2 configuration file} -D
In order to start the Aria2 on boot, add above command to /etc/rc.local(before exit 0). For example:
- Install Web GUI
sudo apt-get install nginx
cd ~
wget https://github.com/mayswind/AriaNg/releases/download/1.1.0/AriaNg-1.1.0.zip
sudo unzip AriaNg-1.1.0.zip -d /var/www/html/ang
Access http://{IP of Raspberry Pi}/ang in browser:
Go to AriaNg Settings->RPC({IP of Raspberry Pi}), Input rpc-secret of Aria2 configuration file on “Aria2 RPC Secret Token”.
Aria2 Status is “Connected” if the parameters are correct.
2. Domain name: Dynu.net
Register new account and create new domain name on Dynu.net
Then setup a cron job to run every 5 minutes to keep your hostnames updated to the most current IP address.
crontab -e
Add this line(replace UUUUU and PPPPP with your username and password):
/5 * * * * echo url="https://api.dynu.com/nic/update?username=UUUUU&password=PPPPP" | curl -k -K -
After IP is updated, you will find it on Control Panel->DDNS Services
Dynu.net provides instruction for Raspberry Pi
3. Install rclone to connect Google drive
Install rclone:
curl https://rclone.org/install.sh | sudo bash
Configure rclone to connect Google Drive
rclone config
Define the name to mark the Google drive
Open the browser and input the link in above picture
Copy and paste the key code
4. Auto upload script
I write a script to upload the file to Google Drive automatically when the download task is complete
Download script:
cd ~
wget https://github.com/YifangY/IoTProject2019/blob/master/uploadtogoogle.sh
chmod +x uploadtogoogle.sh
Update parameter to match your system, such as REMOTENAME, REMOTEFOLDER, ArialocalFolder
Add this line in crontab:
*/5 * * * * /usr/bin/flock -xn /tmp/uploadtogoogle.lock -c '/home/pi/uploadtogoogle.sh'
flock provide mutual exclusion to guarantee only one “uploadtogoogle.sh” is running.
5. Optional: Baidupcs-web
If you need to transfer file from Baidu Wangpan to Google Drive, Baidupcs-web is a good Linux client to access Baidu Wangpan. Baidupcs-web bases on BaiduPCS-Go. You can find the latest release from this link.
wget https://github.com/liuzhuoling2011/baidupcs-web/releases/download/3.6.7/BaiduPCS-Go-3.6.7-linux-arm.zip
unzip BaiduPCS-Go-3.6.7-linux-arm.zip
There is only one binary file in zip which could be executed directly
Access http://{IP of Raspberry Pi}:5299 in browser: