title: Firewall and FTP Directory Listing in C#
body: <p>I am trying to get a directory listing of an FTP site but am having issues connecting and retrieving the listing. I believe the problem is with the windows firewall for Windows 2008 Server R2. Here is the code:</p>
  
  <pre><code>        try
          {
              // Get the object used to communicate with the server.
              FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://127.0.0.1");
              request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
  
              request.UsePassive = false;
  
              // This example assumes the FTP site uses anonymous logon.
              request.Credentials = new NetworkCredential("user", "pass");
              request.Proxy = HttpWebRequest.DefaultWebProxy;
              FtpWebResponse response = (FtpWebResponse)request.GetResponse();
  
              Stream responseStream = response.GetResponseStream();
              StreamReader reader = new StreamReader(responseStream);
  
              Label1.Text = reader.ReadToEnd();
  
              reader.Close();
              response.Close();
          }
          catch (Exception ex)
          {
              Label1.Text = ex.Message;
          }
  </code></pre>
  
  <p>I am wondering what firewall settings or ports need to be opened to allow this action to happen. I enabled all incoming/outgoing traffic on ports 21 and 20 and that didn't work so I allowed all traffic incoming/outgoing for all ports and that worked. However, opening up every port like that is not a viable solution :)</p>