“请求的 URI 无效"在使用 FtpWebRequest 上传期间

编程入门 行业动态 更新时间:2024-10-28 12:25:14
本文介绍了“请求的 URI 无效"在使用 FtpWebRequest 上传期间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我尝试将文件上传到 FTP 服务器上的目录.我将此方法与 FtpWebRequest 一起使用.我想为该用户上传一个文件到主目录,但我总是收到以下错误消息:

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:

请求的 URI 对于此 FTP 命令无效.

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(); }

推荐答案

如果你想上传一些东西,你会 必须为 FTPClient 提供文件名.

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:25:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1572724.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:上传   URI   quot   FtpWebRequest

发布评论

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

>www.elefans.com

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