2017-01-27 206 views
1

我不斷收到錯誤「遠程服務器返回錯誤:(530)未登錄。」當調用FtpWebRequest.GetResponse()時。我懷疑這是因爲我錯誤地配置了FTP站點進行基本身份驗證,但我不確定。我已閱讀其他帖子,但解決方案似乎圍繞着NetworkCredential對象中指定的錯誤憑證。我希望能夠通過SSL將憑據傳遞到FTP站點。我已將問題隔離到測試項目。這,主要是從MSDN https://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest.enablessl(v=vs.110).aspx複製:FtpWebRequest:遠程服務器返回錯誤:(530)未登錄

public static void Main(string[] args) 
{ 
    // Only use this to get around issues with self-signed certificates... 
    ServicePointManager.ServerCertificateValidationCallback = 
     delegate (object s, X509Certificate certificate, X509Chain chain, 
     SslPolicyErrors sslPolicyErrors) { return true; }; 

    ListFilesOnServerSsl(new Uri("ftp://127.0.0.1:21")); 

    Console.WriteLine("Press any key..."); 
    Console.ReadKey(); 
} 

public static bool ListFilesOnServerSsl(Uri serverUri) 
{ 
    // The serverUri should start with the ftp:// scheme. 
    if (serverUri.Scheme != Uri.UriSchemeFtp) 
    { 
     return false; 
    } 
    // Get the object used to communicate with the server. 
    FtpWebRequest request = (FtpWebRequest)WebRequest.Create(serverUri); 
    request.Method = WebRequestMethods.Ftp.ListDirectory; 
    request.UseBinary = false; 
    request.EnableSsl = true; 

    // Need to use credentials to log in... 
    request.Credentials = new NetworkCredential("TestFtpUser", "IDontKnow"); 

    // Get the ServicePoint object used for this request, and limit it to one connection. 
    // In a real-world application you might use the default number of connections (2), 
    // or select a value that works best for your application. 

    ServicePoint sp = request.ServicePoint; 
    Console.WriteLine("ServicePoint connections = {0}.", sp.ConnectionLimit); 
    sp.ConnectionLimit = 1; 

    FtpWebResponse response = (FtpWebResponse)request.GetResponse(); 
    Console.WriteLine("The content length is {0}", response.ContentLength); 
    // The following streams are used to read the data returned from the server. 
    Stream responseStream = null; 
    StreamReader readStream = null; 
    try 
    { 
     responseStream = response.GetResponseStream(); 
     readStream = new StreamReader(responseStream, System.Text.Encoding.UTF8); 

     if (readStream != null) 
     { 
      // Display the data received from the server. 
      Console.WriteLine(readStream.ReadToEnd()); 
     } 
     Console.WriteLine("List status: {0}", response.StatusDescription); 
    } 
    finally 
    { 
     if (readStream != null) 
     { 
      readStream.Close(); 
     } 
     if (response != null) 
     { 
      response.Close(); 
     } 
    } 


    Console.WriteLine("Banner message: {0}", 
     response.BannerMessage); 

    Console.WriteLine("Welcome message: {0}", 
     response.WelcomeMessage); 

    Console.WriteLine("Exit message: {0}", 
     response.ExitMessage); 
    return true; 
} 

接下來是在IIS中在我的本地創建FTP站點的截圖:

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

我注意到IIS在設置基本身份驗證時沒有問我密碼。我不知道這是爲什麼。我應該不使用FTP站點的基本身份驗證嗎?

非常感謝提前!

回答

0

事實證明,我沒有在機器上配置本地用戶帳戶,以便在IIS中配置ftp站點時與「指定的用戶」匹配。進入「控制面板」=>「用戶帳戶」=>「用戶帳戶」=>「管理用戶帳戶」=>「管理用戶帳戶」=>添加,並將用戶添加到本地計算機後,消息「 530)未登錄「已消失。

相關問題