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();