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 上传期间


基础教程推荐
- rabbitmq 的 REST API 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- MS Visual Studio .NET 的替代品 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- c# Math.Sqrt 实现 2022-01-01