quot;Requested URI is invalidquot; during upload with FtpWebRequest(“请求的 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 上传期间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:“请求的 URI 无效"在使用 FtpWebRequest 上传期间


- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 输入按键事件处理程序 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01