在 C# 中通过 FTP 编辑文本文件?
基本上,我想使用以下代码来编辑 C# 文件:
var file = new StreamReader("ftp://xxx.xxx.x.x/xxx.txt"); //[ip address/file]
label1.Text = file.ReadLine();
file.Close();
var fw = new StreamWriter("ftp://xxx.xxx.x.x/xxx.txt"); //[ip address/file]
fw.WriteLine(textBox1.Text);
fw.Close();
但它不起作用,我该怎么做?
I want to, basically, use the following code to edit a C# file:
var file = new StreamReader("ftp://xxx.xxx.x.x/xxx.txt"); //[ip address/file]
label1.Text = file.ReadLine();
file.Close();
var fw = new StreamWriter("ftp://xxx.xxx.x.x/xxx.txt"); //[ip address/file]
fw.WriteLine(textBox1.Text);
fw.Close();
But it doesn't work, how do I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
通过 FTP 编辑文件的方法是:
对于步骤 1 和 3,请检查 这个。
Edit file via FTP is:
For steps 1 and 3 check this.
与 ftplib 库相比,FtpWebRequest 看起来非常复杂@ http://ftplib.codeplex.com/
这是他们的例子...
The FtpWebRequest seems very complex compared to the ftplib library @ http://ftplib.codeplex.com/
Here is their example...
查看 .NET 中包含的 FtpWebRequest 类4.0 来帮助解决这个问题。
Check out the FtpWebRequest class that is included in .NET 4.0 to help with this.
正如我所看到的,我有点晚了,但我遇到了和你一样的问题,在我寻找解决方案之后,我找到了一种无需下载和上传文件即可进行更改的方法。
我的目标是在程序结束时保存程序执行期间所做的所有更改,并在程序启动时从存储在 FTP 服务器中的 .txt 文件加载这些数据。
下面是使用的两种方法:
As i see i`m a little late, but i faced the same problem like you, and after i dig for a solution, i found a way to do the changes without downloading, and uploading the file.
My goal was to save all the changes made during the program execution at the closing, and to load these data at program start from a .txt file stored in a FTP server.
Here is the two methods are used: