Tuesday, December 11, 2012

How to make a Raspberry Pi solar-powered FTP server


You've set up your Raspberry Pi using our easy to follow instructions. You've had a gander at our 25 top fun things to do and now you fancy something a bit more involved. How about making a solar-powered FTP server?
You'll always have instant access to all your digital files, from anywhere with an Internet connection, and it won't cost a penny on your electricity bill.

Ordering the sun bed

We'll be using a simple custom-built £25 Raspberry Pi case, with all the right slots for its outputs, that comes with a small solar panel, a battery case and a micro-USB cable. You'll just need to supply your own NiMH rechargeable batteries.

Point your browser over here -- you'll find all the information you need to place an order via PayPal. The maker, Cottonpickers, has an eBay page as well if you're more comfortable making your purchase that way.

Static IP address

Once it's plopped through your letterbox, slot your Pi into the case and hook it up to power and a monitor. Let's start programming. The first step is to make sure the RPi has a static IP address, as we're going to have to poke a hole through our network firewall to allow incoming FTP requests.
In the RPi desktop, double-click the 'LX Terminal' icon to drop into the Terminal. To setup a static IP address, type the following:
sudo nano /etc/network/interfaces
This file controls the IP addressing for the RPi. All you need to do is scroll down slightly to the 'iface eth0' line and remove 'DHCP' and replace it with 'static'. Now, on the line directly below, enter an IP address for your RPi, along with the subnet mask and gateway. Our example looked like this, but yours will be dependent on your home network:
Assuming you don't know these already, you can find your IP address and router settings by consulting your router documentation, or by typing the following into a Terminal on the RPi: ifconfig -a. This will list the current IP address, netmask and gateway as configured by the router's DHCP. All you need to do then is enter the IP address and so on into the 'static' section of the file to make sure the RPi will forever boot with that unique IP addess.
After you've entered the details, exit by pressing Ctrl+X to exit, followed by 'Y' to accept the changes, then press Enter a couple of times to get to the command line. Now type:
sudo /etc/init.d/networking stop
sudo /etc/init.d/networking start

This will restart the networking components with the new IP address in place.


From the Terminal type the following, pressing Enter after each line:
sudo apt-get update
sudo apt-get install vnc-server

When the packages have downloaded and installed, follow the instructions on-screen to setup a password, and confirm it, but answer 'No' to the view-only option.
Now that VNC is installed, we need to make sure it loads up as a service every time the RPi reboots. To do this, from the Terminal type:
sudo nano /etc/init.d/tightvncserver, and press enter
In the editor, type the following:
# /etc/init.d/tightvncserver
# Set the VNCUSER variable to the name of the user to start tightvncserver under
case "$1" in
     su $VNCUSER -c '/usr/bin/tightvncserver :1'
     echo "Starting TightVNC server for $VNCUSER "
     pkill Xtightvnc
     echo "Tightvncserver stopped"
     echo "Usage: /etc/init.d/tightvncserver {start|stop}"
     exit 1
exit 0

Now press 'Ctrl+X', then 'Y' to save, followed by 'Enter' a couple of times to get you back into the Terminal. What we need to do now is edit the permissions of the script we've just created so that it's executable, do this by typing in:
sudo chmod 755 /etc/init.d/tightvncserver, and press Enter.
Finally, we need to add it to the start-up scripts, by typing:
update-rc.d tightvncserver defaults, and press Enter.
What you can do now is unplug the RPi from your monitor and locate it somewhere that has easy access to a network cable, and plenty of sunlight (for the solar cells). If you install the likes of TightVNC Viewer you should be able to point the client to '' (or whatever your static IP address is) and have full access to the RPi and the GUI.


This next part involves setting up the FTP server itself. Again it's not too difficult, and can be configured to your exact preferences later on. From the Terminal, type the following:
sudo apt-get install vsftpd, and press Enter.
Once the VSFTPD (which stands for Very Secure FTP Daemon) packages have downloaded and installed, type:
sudo nano /etc/vsftpd.conf, and press Enter.
This is the configuration file and control for VSFTPD, it allows you to set all sorts of restrictions and policies, so some care is advised. To start with though, we would recommend altering the following lines within the script, either by un-hashing, or typing in 'YES' or 'NO':

The full explanation can be found within the hashed comments in the script itself, but they will suffice for our little project for now. When ready, rave the changes to the script as before.
Finally, reboot the RPi to bring everything you've done so far into effect. To do this, make sure you're in the Terminal, and type:
sudo reboot, and press Enter.

Access external hard drive via FTP

We like to make things easy, so here's our method of accessing an external hard drive attached to one of the RPi's USB ports, via an FTP client.
First, you can hook up an external USB drive to your PC and format it as NTFS, with the volume labelled FTP. When that's complete, plug it in to the RPi and via VNC click 'Yes' to view the drive from within the File Manager.
Make a note of the address of the hard drive -- in our case it came out as /media/FTP. To test FTP access, install an FTP client such as FileZilla and enter the connection details:, replacing the IP address with your own static RPi address.
Username: pi, replace this with the username you set VSFTPD with (default is pi).
Password: raspberry, replace this with user's password (if other than pi).
With luck, you should now have access to the external USB hard drive, via FTP, internal to your own network.

External access

The final part of this project involves granting external FTP access to the RPi. This is also the most ambiguous of the steps, as it all depends on the make and model of your router. For example, on the basic BT model I used it's a simple case of selecting FTP from the pre-defined applications, and assigning it to the internal IP address of the Raspberry Pi.
Yours may be completely different, however. That being the case, please consult your router's documentation, or Google the model and see if there's already an FTP external access tutorial out there.

No comments:

Post a Comment