title: Connecting ftp server with credentials
body: <p>I'm writing a program that uses an ftp server with credentials. I'm trying to retrieve the directory list from the server but when I get to the line:</p>
  
  <pre><code>string line = reader.ReadLine();
  </code></pre>
  
  <p>the string that I get contains only : "Can't open \"host:/lib1\"."</p>
  
  <p>If I try to get another line, the next exception is thrown: The remote server returned an error: (550) File unavailable (e.g., file not found, no access).</p>
  
  <p>I know for sure (using another ftp application) that 'lib1' directory exists on the ftp server and my credentials (username and password) are correct.</p>
  
  <p>Here is my code:</p>
  
  <pre><code> public class FTPClient
  {
      public string UserName { get; set; }
      public string Password { get; set; }
      public string IpAddress { get; set; }
      public int Port { get; set; }
  
      public FTPClient(string _userName, string _password, string _address, int _port)
      {
          UserName = _userName;
          Password = _password;
          IpAddress = _address;
          Port = _port;
      }
  
      public void GetDirectoriesList(string _path)
      {           
          FtpWebRequest request = (FtpWebRequest)WebRequest.Create(new Uri("ftp://" + 
          IpAddress + _path));
          request.UseBinary = true;
          request.Method = WebRequestMethods.Ftp.ListDirectory;
          request.Credentials = new NetworkCredential(UserName, Password);
  
          FtpWebResponse response = (FtpWebResponse)request.GetResponse();
          Stream responseStream = response.GetResponseStream();
          StreamReader reader = new StreamReader(responseStream);
  
          string line = reader.ReadLine();
          while (line!=null)
          {
              ... //do something with line
              line = reader.ReadLine();
          }
          ...
          reader.Close();
          response.Close();
  
  
      }
  </code></pre>
  
  <p>And I use it as follows:</p>
  
  <pre><code>FTPClient ftpClient = new FTPClient("user1", "pass1", "192.168.2.110", 21);
  
          string dirList = ftpClient.GetDirectoriesList("/lib1");
  </code></pre>
  
  <p>Can anyone spot the problem?</p>