ftp上传使用asp,net [英] ftp upload using asp,net
本文介绍了ftp上传使用asp,net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,有人可以帮我上传一个文本文件到ftp本地主机我有一个错误这是我的代码
hello can some one help me to upload a text file to ftp local host i have an error this is my code
string filename = Path.GetFileName("C:\\inetpub\\ftproot\\reg.txt");
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("127.0.0.1 + ftp/reg.txt");
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential("username", "password");
StreamReader sourceStream = new StreamReader("C:\\inetpub\\ftproot\\reg.txt");
byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
request.ContentLength = fileContents.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
response.Close();
requestStream.Close();
sourceStream.Close();
推荐答案
正如错误消息所示,参数为WebRequest.Create
需要是一个有效的URI。您传入的值(127.0.0.1 + ftp / reg.txt)不是有效的URI。
URI应该类似于:
As the error message says, the parameter toWebRequest.Create
needs to be a valid URI. The value you've passed in ("127.0.0.1 + ftp/reg.txt") is not a valid URI.
The URI should look something like:
"ftp://127.0.0.1/reg.txt"
但是,这段代码没有任何意义。您正在从服务器获取文件,并尝试通过FTP将其上传到同一服务器上的相同位置 !
这篇关于ftp上传使用asp,net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文