title: Running an ftp server on nixos
body: <p>I would like to run an ftp server on a nixos host.  I am using vsftpd, though could use something else if that would make a difference.</p>
  
  <p>The ftp works fine on localhost, but the firewall is blocking me for remote usage.  I have allowed TCP port 21, but that is not enough.</p>
  
  <p>How should I configure the firewall to allow ftp connections (including writing to the ftp server)?</p>
  
  <p>Here is the code that I currently have:</p>
  
  <pre><code>{
  networking.firewall = { allowedTCPPorts = [ 20 21 ];
  #                        connectionTrackingModules = [ "ftp" ];
                        };
  
    services.vsftpd = {
      enable = true;
  #   cannot chroot &amp;&amp; write
  #    chrootlocalUser = true;
      writeEnable = true;
      localUsers = true;
      userlist = [ "martyn" "cam" ];
      userlistEnable = true;
    };
  }
  </code></pre>
  
  <p>With the above, any use of ftp from off-host fails:</p>
  
  <pre><code>ftp&gt; put dead.letter
  200 PORT command successful. Consider using PASV.
  425 Failed to establish connection.
  </code></pre>
  
  <p>Use of passive mode (e.g., with <code>ftp -p</code>) doesn't seem to help here:</p>
  
  <pre><code>ftp&gt; put dead.letter
  227 Entering Passive Mode (192,168,0,7,219,202).
  ftp: connect: Connection timed out
  </code></pre>
  
  <p>Testing on a throwaway host with the firewall disabled </p>
  
  <p>networking.firewall.enable = false;</p>
  
  <p>Allows <code>ftp -p</code> to work; though of course turning off the firewall is not an attractive option.</p>
  
  <p>Thanks for any help and pointers,</p>