我試圖上傳FTP文件夾中的文件,但出現以下錯誤。將文件上傳到名稱爲特殊字符的ftp文件夾
The remote server returned an error: (550) File unavailable (e.g., file not found, no access)
我使用下面的示例來測試這一點:
// 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
但這並沒有幫助
感謝您的時間和幫助文件。
問題出在url:在每個文件夾名稱後面使用「//」而不是「/」@Ankit – Prabu