"请求URI是无效的"上载过程中的FtpWebRequest

编程入门 行业动态 更新时间:2024-10-28 18:32:26
本文介绍了"请求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

本文发布于:2023-11-09 15:27:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1572727.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:过程中   QUOT   URI   FtpWebRequest

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!