title: ASP.NET C# search for files on ftp (better code)
body: <p>Hoping I explain this like I am thinking</p>
  
  <p>I have a web app which has products, from a list of suppliers. e.g. www.example.com.au/Browse.aspx?SupplierID=XYZ displays products for XYZ suppliers only. This then goes to the details page www.example.com.au/Product.aspx?ProductID=123. This page displays a list of details for that product (gallery of images, product data sheets, i.e PDFs, etc).</p>
  
  <p>Now, each supplier is given an ftp account, where he can upload their product information - <a href="ftp://resources.example.com.au" rel="nofollow">ftp://resources.example.com.au</a>, and this is accessible via resources.example.com.au/*. So, let's say supplier XYZ will have something like:</p>
  
  <pre><code>resources.example.com.au/XYZ/123.jpg &lt;== main product image
  resources.example.com.au/XYZ/123_a.jpg &lt;== secondary image
  resources.example.com.au/XYZ/123_b.jpg &lt;== secondary image
  resources.example.com.au/XYZ/123_c.jpg &lt;== secondary image
  </code></pre>
  
  <p>(Due to application requirement, the web app sits on a different server, than the resources folder)</p>
  
  <p>Now, to get the list of related product images, i have the following:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>public List&lt;string&gt; GetFiles(string strDirectoryName, string strStartsWith)
  {
      List&lt;string&gt; files = new List&lt;string&gt;();
  
      FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(new Uri(strFTPUrl + strDirectoryName));
      request.Method = WebRequestMethods.Ftp.ListDirectory;
      request.Credentials = new NetworkCredential(strFtpUser, strFtpPassword);
  
      FtpWebResponse response = (FtpWebResponse)request.GetResponse();
      Stream responseStream = response.GetResponseStream();
      StreamReader reader = new StreamReader(responseStream);
  
      while (!reader.EndOfStream)
      {
          string filename = reader.ReadLine().ToString();
          if (filename.Length &gt; 4)
          {
              if (!string.IsNullOrEmpty(strStartsWith))
              {
                  if (filename.StartsWith(strStartsWith, StringComparison.OrdinalIgnoreCase))
                  {
                      files.Add(filename);
                  }
              }
          }
      }
  
      response.Close();
      responseStream.Close();
      reader.Close();
  
      return files;
  }
  </code></pre>
  
  <p>Unfortunately, this function goes through all the files (which could be around 100,000's), and selects only the file i need. </p>
  
  <p>My question: is there a better way to filter only the images i need, rather than going through the entire directory?</p>
  
  <p>Or, perhaps another way to get these images? </p>