title: Using TCPClient with RAW FTP to retrieve file
body: <p>I get the following message back when trying to retrieve a file using TCPClient and RAW FTP:</p>
  
  <blockquote>
    <p>425 Failed to establish connection.</p>
  </blockquote>
  
  <p>I connect using :</p>
  
  <pre><code>using (TcpClient client = new TcpClient("ServerName", 21))
  using (NetworkStream stream = client.GetStream())
  using (StreamReader reader = new StreamReader(stream))
  using (StreamWriter writer = new StreamWriter(stream))
  {
  </code></pre>
  
  <p>Then I login to the server fine using <code>USER ****</code> and <code>PASS ***</code>. I manage to change to the correct directory using <code>CWD /**/**</code>, as mentioned this all works fine and i get the expected response messages.</p>
  
  <p>However when the following code executes the message mentioned above is all i receive.</p>
  
  <pre><code>lineToSend = "PASV";
  Program.logger.Add("Sending to server: " + lineToSend, 1);
  writer.WriteLine(lineToSend);
  while (!stream.DataAvailable)
  {
      Program.logger.Add(stream.DataAvailable.ToString(), 1);
      Program.logger.Persist();
      Thread.Sleep(1000);
  
  }
  lineWeRead = reader.ReadLine();
  Program.logger.Add("Received from server: " + lineWeRead, 1);
  Program.logger.Persist();
  
  lineToSend = "RETR file.txt";
  Program.logger.Add("Sending to server: " + lineToSend, 1);
  writer.WriteLine(lineToSend);
  while (!stream.DataAvailable)
  {
      Program.logger.Add(stream.DataAvailable.ToString(), 1);
      Program.logger.Persist();
      Thread.Sleep(1000);
  }
  
  Program.logger.Add("Loop Exited: " + stream.DataAvailable.ToString(), 1);
  Program.logger.Persist();
  lineWeRead = reader.ReadLine();
  Program.logger.Add("Received from server: " + lineWeRead, 1);
  Program.logger.Persist();
  </code></pre>
  
  <p>I am fairly new to C#.NET and have been asked specifically to use this method of connecting and not the httpWebRequest.</p>
  
  <p>The file I am trying to receive is a text file containing only "Get this message" but will be bigger when used. Any help is much appreciated.</p>