【发布时间】:2017-01-03 06:54:55
【问题描述】:
我正在尝试在 FTP 文件夹上上传文件,但出现以下错误。
远程服务器返回错误:(550) 文件不可用(例如, 找不到文件,无法访问)
我正在使用以下示例对此进行测试:
// Get the object used to communicate with the server.
string path = HttpUtility.UrlEncode("ftp://host:port//01-03-2017/John, Doe S. M.D/file.wav");
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(path);
request.Method = WebRequestMethods.Ftp.UploadFile;
// This example assumes the FTP site uses anonymous logon.
request.Credentials = new NetworkCredential("user", "password");
// Copy the contents of the file to the request stream.
StreamReader sourceStream = new StreamReader(@"localpath\example.wav");
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();
- 我可以上传父文件夹
01-03-2017上的文件,但不能上传目标文件夹ROLLINS, SETH S. M.D中的文件,目标文件夹中显然有特殊字符。 - 我可以使用 FileZilla 上传文件
- 我尝试过
HttpUtility.UrlEncode,但没有帮助
感谢您的时间和帮助。
【问题讨论】:
-
问题出在网址上:在每个文件夹名称后使用“//”而不是“/”@Ankit