title: download log file from ftp server to stream and get the last line of the log file using c#
body: <p>I am trying to download a log file to my program without save it to my local machine, and get the last line of the log. </p>
  
  <p>can anyone send me an example of it or look at the code and tell me what is wrong.</p>
  
  <p>thanks </p>
  
  <pre><code>FileStream outputStream = new FileStream(uri, FileMode.Create);
  
  request = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));
  request.Method = WebRequestMethods.Ftp.DownloadFile;
  request.UseBinary = true;
  request.Credentials = new NetworkCredential(userName, Password);
  FtpWebResponse response = (FtpWebResponse)request.GetResponse();
  Stream ftpStream = response.GetResponseStream();
  long cl = response.ContentLength;
  int readCount;
  
  readCount = ftpStream.Read(b, 0, b.Length);
  while (readCount &gt; 0)
  {
      outputStream.Write(b, 0, readCount);
      readCount = ftpStream.Read(b, 0, b.Length);
  }
  
  temp2 = System.Text.Encoding.UTF8.GetString(b);
  temp1 = temp2.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
  LastItem = temp1.Last();
  
  
  ftpStream.Close();
  outputStream.Close();
  response.Close(); 
  </code></pre>