本文介绍了"请求URI是无效的"上载过程中的FtpWebRequest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想上传文件到FTP服务器上的目录。我用这个方法,的FtpWebRequest 。我想一个文件上传到主目录里的用户,但我总是得到以下错误消息:
请求的URI是此FTP命令无效。
可以是什么问题呢?我试图使用被动模式关闭,但它仍然是相同的。
静态无效FtpUpload(){ //获取用于与服务器通信的对象。 的FtpWebRequest请求=(的FtpWebRequest)WebRequest.Create(ftp://12.22.44.45); request.Method = WebRequestMethods.Ftp.UploadFile; request.UsePassive = FALSE; //这个例子假设FTP站点使用匿名登录。 request.Credentials =新的NetworkCredential(pokus,密码); //文件的内容复制到请求流。 StreamReader的的SourceStream =新的StreamReader(路径); 字节[] = fileContents Encoding.UTF8.GetBytes(sourceStream.ReadToEnd()); sourceStream.Close(); request.ContentLength = fileContents.Length; 流requestStream = request.GetRequestStream(); requestStream.Write(fileContents,0,fileContents.Length); requestStream.Close(); FtpWebResponse响应=(FtpWebResponse)request.GetResponse(); Console.WriteLine(上传文件的完整,状态{0},response.StatusDescription); response.Close();}解决方案
如果您要上传的东西,你会have提供FTPClient一个文件名。
的FtpWebRequest请求=(的FtpWebRequest)WebRequest.Create(ftp://12.22.44.45/myNewFile.dat);I trying upload file to a directory on a FTP server. I used this method with FtpWebRequest. I would like to upload one file to a home directory for this user, but I always get the following error message:
The requested URI is invalid for this FTP command.
What can be problem? I tried use passive mode off, but it still the same.
static void FtpUpload() { // Get the object used to communicate with the server. FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://12.22.44.45"); request.Method = WebRequestMethods.Ftp.UploadFile; request.UsePassive = false; // This example assumes the FTP site uses anonymous logon. request.Credentials = new NetworkCredential("pokus", "password"); // Copy the contents of the file to the request stream. StreamReader sourceStream = new StreamReader(path); byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd()); sourceStream.Close(); request.ContentLength = fileContents.Length; Stream requestStream = request.GetRequestStream(); requestStream.Write(fileContents, 0, fileContents.Length); requestStream.Close(); FtpWebResponse response = (FtpWebResponse)request.GetResponse(); Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription); response.Close(); }解决方案
If you want to upload something, you'll have to provide the FTPClient with a filename.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://12.22.44.45/myNewFile.dat");
更多推荐
"请求URI是无效的"上载过程中的FtpWebRequest
发布评论