Monday, March 04, 2013

Raspberry Pi–Using FTP between 2 Pi’s programmatically

I have a need to transfer sensor data periodically from on Pi to another. For no good reason, I decided to use FTP for this. Actually, as it turned out, it was a good decision, since the process works well and the overhead involved, i.e. installation and programming as well as CPU time, is minimal.

Both Pi’s are running Raspbian Wheezy, latest version.

This is what I did:

On the Pi that has the data that I want, I installed vsftp thusly:

sudo apt-get install vsftpd

Once the installation finished I adjusted the configuring parameters:

sudo nano /etc/vsftpd.conf

Once this file opened up, I removed the # tags in front of local_enable=YES and write_enable=YES, changed anymous_enable to NO, then closed and saved the file when I was prompted.

Next, I restarted the service like this:

sudo service vsftpd restart

On the Pi that needs the data I do the retrieving via FTP in a python program using a standard Python library, surprising called ftplib.

Here’s the program:

   1: import ftplib
   2: sftp = ftplib.FTP('192.168.0.151','pi','mypassword')
   3: sftp.cwd("pythonprogs")
   4: gFile = open("distancemeasurement","wb")
   5: sftp.retrbinary("RETR distancemeasurement",gFile.write)
   6: sftp.quit()
Line 3 (cwd) is Change Working Directory)

That’s it! Pretty straightforward, I think.

1 comment:

Deba Sheesh said...

This is really an important blog with many helpful information. I have been searching for a long time for this types of content. Keep up posting more and thanks for your great staff.
Battery Operated Ultrasonic Level Sensor