0

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.

can anyone send me an example of it or look at the code and tell me what is wrong.

thanks

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 > 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(); 
blfuentes
  • 2,731
  • 5
  • 44
  • 72
Ek2300
  • 1
  • 1
  • You cant tell what is wrong with your code? :) – Renatas M. Oct 23 '14 at 07:44
  • possible duplicate of [How to read a text file reversely with iterator in C#](http://stackoverflow.com/questions/452902/how-to-read-a-text-file-reversely-with-iterator-in-c-sharp) – Renatas M. Oct 23 '14 at 07:47

0 Answers0