优艾设计网

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

优艾设计网 https://www.uibq.com 2023-04-23 15:01 出处:网络 作者:在线设计
大家好,有个问题请教一下大家。我用vsftpd搭建了一个服务器,每一分钟向优艾设计网_设计百科其中的一个log文本不停传送一些测试相关信息。现在我想做一个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); } }

感谢阅览。


0

精彩评论

暂无评论...
验证码 换一张
取 消