Linux – FTP uploads have incorrect permissions when using vsftpd

debianftplinux

I recently set up an FTP site using VSFTPD on Debian, and am running into an issue with uploaded directories not being able to be accessed. Files are okay but when I try to upload a directory or change into a freshly uploaded empty directory, I get the following error:

Failed to change directory.

If I go in through the shell as and chmod the correct permissions, I can access the directory with no issues. If I go in through the shell and make a new directory, there is also no issue with it, this issue only seems to be on directories uploaded via an FTP client.

Any help on this is greatly appreciated. I am running Debian 7.5 (Wheezy) and the client I am using to connect is WinSCP from a Windows 7 system. I am using a chroot jail, where the the user is jailed to their home directory (which is not writeable).

Best Answer

Well, I think there may be two causes:

  1. You log in to the FTP server as anonymous, but the uploaded directories are chown'ed to another user, and they have permissions 0600, so they become unavailable to ftp (or another user set by ftp_username) to which anonymous users are mapped by the vsftpd daemon.

    Try to set the following in your vsftpd.conf:

    chown_uploads=YES
    chown_upload_mode=0644
    chown_username=ftp
    

    Note that you may want to change ftp to something else if you already changed ftp_username or guest_username.

  2. You said that uploaded files are OK, but directories are broken. That makes me think that there is something wrong with umask, perhaps it is set to something like 011 or 033 that causes the execute bit to be disabled, and therefore you cannot list directories.

    Try to fix that by setting umask values to 022 in the vsftpd.conf:

    anon_umask=022
    local_umask=022