title: Read a CSV file from FTP Server Using C#
body: <p>I am trying to read a CSV file from ftp server using c# but problem is it does not allow me to read and throwing this error <br/></p>
  
  <blockquote>
    <p>The remote server returned an error: (530) Not logged in.<br/></p>
  </blockquote>
  
  <p>I have spent lot of time on researching this issue unfortunately I could not find the solution yet. Any help would be highly appreciated.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>StringBuilder result = new StringBuilder();
  FtpWebRequest reqFTP;
  try
  {
      String ftpserver = "ftp://domain.com/StatusChanges_20120922_043057.csv";
  
      reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpserver));
      reqFTP.UsePassive = false;
      reqFTP.UseBinary = true;
      reqFTP.Credentials = new NetworkCredential("test@domain.com", "password");
      reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
      reqFTP.Proxy = GlobalProxySelection.GetEmptyWebProxy();
      FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
  
      StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8);
      string line = "";
  
      while (reader.Peek() &gt; -1)
      {
          line = reader.ReadLine();
          Console.WriteLine(line);//**********HTML was wrote out here*************
      }
  
      if (result.ToString().LastIndexOf('\n') &gt;= 0)
          result.Remove(result.ToString().LastIndexOf('\n'), 1);
      reader.Close();
      response.Close();
  
      return result.ToString();
  }
  catch (Exception ex)
  {
  }
  </code></pre>