0
我有一段非常簡單的代碼。 一切都寫得正確,沒有錯別字,我跟同事聊天,但我們兩個人根本沒有理想,錯誤在這裏。此命令的FTP WebException-URI無效
它順利地通過繼續彈出GetRequestStream()異常彈出。它找到文件,正確編碼它,但似乎無法連接到服務器。
這是代碼:
public class WebRequestUploadExample
{
public void WebRequestUpload()
{
// Get the object used to communicate with the server.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(@"ftp://xxxxx");
request.Method = WebRequestMethods.Ftp.UploadFile;
// This example assumes the FTP site uses anonymous logon.
request.Credentials = new NetworkCredential("xxxxx", "xxxxx");
// Copy the contents of the file to the request stream.
StreamReader sourceStream = new StreamReader(@"D:\ftpTest\Test\Test.txt");
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();
}
}
顯示我們一個確切的異常信息,其調用堆棧和理想的日誌文件:https://stackoverflow.com/q/9664650/850848 –
編輯您的憑據進行於事無補。一旦你在互聯網上發佈任何東西,你就無法收回。你必須改變你的憑證。並將FTP服務器上的數據視爲受損。 –