Saturday, June 26, 2010

vsftpd: FTP Server for DD-WRT

I generally prefer Samba over FTP as it gives a better experience by allowing user to access the files as if they're still on local disk. And, unlike FTP, media files can be played directly from Samba share. But one might still need FTP server as it offers better performance over Samba.

If the router has at least 8MB flash ROM and happens to run DD-WRT MEGA build, very likely there is a proftpd FTP server built in. But here I'll take some extra trouble to use lightweight vsftpd instead.

So why vsftpd? The main reason is its size. The proftpd is 500KB while vsftpd is only 100KB! This makes it perfect for embedded systems. Also, vsftpd is easy to use and setup.

  1. Disable stock ProFTPD server
    For DD-WRT, it's in Services->NAS. Set it to Disable then click "Apply Settings".

  2. Install vsftpd
    Assume you have followed previous tutorials and has a working opkg system, now use PuTTY to log in the router and run
    opkg install vsftpd

  3. (optional)Add a user for anonymous FTP access
    *ignore this part if you've follow the Samba guide, then this user is already in the system.

    Create or add to /opt/etc/init.d/adduser with following line:

    grep -q nobody /etc/passwd || echo 'nobody:x:65534:65534:nobody:/mnt:/bin/false' >> /etc/passwd

    Above is one single line and will create a new user "nobody" with no valid password and login shell(thus can't be used for login). Then set it to run during boot up:

    chmod a+x /opt/etc/init.d/adduser
    ln -s /opt/etc/init.d/adduser /opt/etc/init.d/S05adduser

  4. vsftpd.conf, the configuration file for vsftpd
    Edit file /opt/etc/vsftpd.conf with below(delete all previous contents if the file is not empty)

    background=YES
    listen=YES
    listen_port=21
    #Change it if you want to use other port
    anonymous_enable=YES
    #Set it to NO if you don't want anonymous FTP access
    ftp_username=nobody
    #local user used for anonymous FTP access, here is "nobody"
    local_enable=YES
    write_enable=YES
    local_umask=022
    check_shell=NO
    session_support=NO

    For a full list of options, please refer to vsftpd website. These basic options here should be enough for home use. With the settings above, the anonymous user will be locked to "/mnt" folder(if you enable the anonymous option). Can also login with other valid user accounts like "root" or "share" with no restriction.

  5. Set vsftpd to run as a service
    Create file /opt/etc/init.d/vsftpd(delete all previous contents if the file is not empty)

    [ -d /var/run/vsftpd ] || mkdir /var/run/vsftpd
    kill -9 $(pidof vsftpd)
    vsftpd /opt/etc/vsftpd.conf

    Then set it to run as a service

    chmod a+x /opt/etc/init.d/vsftpd
    ln -s /opt/etc/init.d/vsftpd /opt/etc/init.d/S60vsftpd

9 comments:

Jockl said...

I am stuck with getting vsftpd running.
I followed every step of your tutorial, but somehow i have to run
Code:
vsftpd /opt/etc/vsftpd.conf

manually via putty after reboot to get the process up, though i have the file vsftpd in /opt/etc/init.d containing
Code:
[ -d /var/run/vsftpd ] || mkdir /var/run/vsftpd
kill -9 $(pidof vsftpd)
vsftpd /opt/etc/vsftpd.conf

and the corresponding link S60vsftpd is also present..

The folder /var/run/vsftpd is created after reboot, but somehow vsftpd /opt/etc/vsftpd.conf isnt executed..

Any idea why the vsftpd process doesnt start or what i can try? Oh and thank you for this blog, this is my first linux experience so far and its really helpful having a guide like this.

ccdoggy said...

Can we get an addition of a walk-through on how to access from the net?

comdotlinux said...

First of all great series of posts! Really helpful for people who do want to use but do not have time to understand all this.

Jockl:
The init.d script kills itself that's why vsftpd is not run! ;-)
just move vsftp to Vsftp
i.e.
mv /opt/etc/init.d/vsftpd /opt/etc/init.d/Vsftpd
mv /opt/etc/init.d/S60vsftpd /opt/etc/init.d/S60Vsftpd

Not it should run fine.

pepinot said...

I encounter the same problem as Jockl

I did followed anjanaya, move asll vsftp to Vsftp.

vsftp still not start after router reboot. :(

Alex said...

There are two letters and a space missing from the example script. It should actually read thus:

if [ -d /var/run/vsftpd ] || mkdir /var/run/vsftpd
kill -9 $(pidof vsftpd)
vsftpd /opt/etc/vsftpd.conf

Alex said...

Scratch that; it's late and I'm tired. It works as-is. Assuming one has followed all the preceding instructions, that is...

myrasingh said...

If your Epson printer offline isn't always working properly, there may be some technical issues together with your printer like: printer driver related issues, software program issues or hardware problems and many others meanwhile you could touch a tech assist corporation.
epson printer offline

aditya said...


Very wonderful informative article. I appreciated looking at your article. Very wonderful reveal. I would like to twit this on my followers. Many thanks! edublackboards

Valluva said...

Thanks For Your Blog
Expert Online Chemistry Tutor
Chemistry With Affordable Online Lessons

Post a Comment