title: Listing server folders and sub folders using C# FtpWebRequest
body: <p>I am trying to get full list of files, directories and sub-directories on tree view using <code>StreamReader</code>. The problem is it took too long and throws *"Operation time out exception" and shows only one level. </p>
  
  <p>Here is my code</p>
  
  <pre><code>public void getServerSubfolder(TreeNode tv, string parentNode) {
    string ptNode;
    List&lt;string&gt; files = new List&lt;string&gt; ();
    try { 
      FtpWebRequest request = (FtpWebRequest) WebRequest.
      Create(parentNode);
      request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
  
      request.Credentials = new NetworkCredential(this.userName, this.Password);
      request.UseBinary = true;
      request.UsePassive = true;
      request.Timeout = 10000;
      request.ReadWriteTimeout = 10000;
      request.KeepAlive = false;
      FtpWebResponse response = (FtpWebResponse) request.GetResponse();
      Stream responseStream = response.GetResponseStream();
      StreamReader reader = new StreamReader(responseStream);
      string fileList;
      string[] fileName;
      //MessageBox.Show(reader.ReadToEnd().ToString());
      while (!reader.EndOfStream) {
        fileList = reader.ReadLine();
        fileName = fileList.Split(' ');
        if (fileName[0] == "drwxr-xr-x") {
          // if it is directory
          TreeNode tnS = new TreeNode(fileName[fileName.Length - 1]);
          tv.Nodes.Add(tnS);
          ptNode = parentNode + "/" + fileName[fileName.Length - 1] + "/";
          getServerSubfolder(tnS, ptNode);
        } else files.Add(fileName[fileName.Length - 1]);
      }
      reader.Close();
      response.Close();
    } catch (Exception ex) {
      MessageBox.Show("Sub--here " + ex.Message + "----" + ex.StackTrace);
    }
  }
  </code></pre>