Tag Archives: FTP

BeagleBone FTP Server

BeagleBone FTP Server

The BeagleBone has multiple text editors available onboard, including vi and vim. I can stumble around (badly) in vi. Using Vim is a little prettier, but not much – I’m really much more of a modal-editor guy. On the Mac, I use BBEdit when I’m not using XCode for iPhone and iPad development.

So my goal is to be able to easily edit on my Mac. BBEdit has a very slick ability to edit files via FTP, so that’s my next step.

Oddly, the BeagleBone doesn’t have an FTP server available in the default distribution. (or if it does, I couldn’t find it)

One skill I know I need to brush up on is acquiring, building, and installing packages in Linux. Since I wanted a quick-and-dirty FTP server running without too much fuss, I naturally looked to Python.

Python is a terrific “scripting” language, and my go-to tool for a lot of tasks.

There is a very nice FTP Server library available: pyftpdlib.

I grabbed this using wget, then did the unzip/untar dance:

    gunzip pyftp*
    tar -xf pyftp*.tar

Installation was simple. The setup python program failed, so I just manually moved the pyftpdlib directory into /usr/lib/python2.7/.

Last but not least, I whipped up a small Python program by modifying the quickstart and demo examples just a bit:

    # FTP server

    from pyftpdlib import ftpserver
    authorizer = ftpserver.DummyAuthorizer()
    authorizer.add_user("root", "12345", "/home/root", perm="elradfmw")
    handler = ftpserver.FTPHandler
    handler.authorizer = authorizer
    address = ("", 21)
    ftpd = ftpserver.FTPServer(address, handler)
    ftpd.serve_forever()

Take that code, stuff it into a file with a .py extension (e.g. ftpserver.py), and invoke it:

    python ftpserver.py

And there you go – FTP access to the home directory of user root.

Now, is this what you’d use to server files to the world at large? Maybe – it looks like a very complete implementation, although I’m no FTP expert.
But it’s perfect for my local development purposes.

The only thing that would be nice is to have it auto-start. That’s pretty easy to do as well, at least in the simple case.

The directory /etc/init.d contains scripts that are executed upon system startup. We place a very simple shell script there, which I called ftpserver:

    #!/bin/sh
    python /home/root/ftpserver.py

This will run the Python FTP server program (which in this case is located in the root account’s home directory – it could be located elsewhere of course).
Once you create this script, don’t forget to make it executable by doing chmod +x ftpserver.

Although this works, our script should really be more compliant and let us stop and restart the server. I plan to address that soon!

Advertisements