怎样winform中远程获取ftp服务器上的数据流?

新手上路,请多包涵

大家好,有个问题请教一下大家。我用vsftpd搭建了一个服务器,每一分钟向其中的一个log文本不停传送一些测试相关信息。现在我想做一个winform测试程序。远程实时获取ftp上传的数据流。理想界面是点击按钮,可以一行一行远程读取log文本数据,并显示在文本框内。
如下图所示
图片描述

我只能想到下面的做法,但是这样并不能实时更新数据流。希望能得到大家的帮助。


 private void button1_Click(object sender, EventArgs e)
        {
            WebClient wc = new WebClient();
            String url = "ftp://192.168.101.1/var/gps/" + "gps_log";
            wc.Credentials = new NetworkCredential("root", "k21cm");
            wc.Proxy = null;
            try
            {
                byte[] newFileData = wc.DownloadData(url);
                string fileString = System.Text.Encoding.UTF8.GetString(newFileData);
                richTextBox1.Text = fileString;
                //Stream stream;
                //StreamReader streamreader;
                //stream = wc.OpenRead("ftp://192.168.101.1/var/gps/gps_log");
                //streamreader = new StreamReader(stream, System.Text.Encoding.Default);
                //while (streamreader.ReadLine() != null)
                //{
                //    string str = streamreader.ReadLine();
                //    Console.WriteLine(str);
                //}
            }
            catch (WebException ex) {
                Console.WriteLine(ex);
            }
        } 

感谢阅览。

阅读 3k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进