我正在尝试将日志文件下载到我的程序而不将其保存到我的本地计算机,并获取日志的最后一行。
任何人都可以给我一个例子,或者查看代码并告诉我出了什么问题。
谢谢
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();