使用FtpWebRequest尝试连接FTPS时抛出异常c#“ - 对SSPI的调用失败,请参阅内部异常”

时间:2015-06-21 19:35:46

标签: c# .net ftpwebrequest ftps

我正在尝试更新一些FTP代码,因为我正在连接的服务器正在强制FTPS。

我得到的例外情况如下:

  

Message =对SSPI的调用失败,请参阅内部异常。

我用来连接的代码如下:

public bool CheckFtpFile(string aFolderName, string aFileName)
{

    FtpWebRequest request;
    string absoluteFileName = Path.GetFileName(aFileName);


    request = WebRequest.Create(new Uri(string.Format(@"ftp://{0}/{1}/{2}", ftpServer, aFolderName, absoluteFileName))) as FtpWebRequest;
    request.Credentials = new NetworkCredential(userName, passWord);
    request.EnableSsl = true;
    request.Method = WebRequestMethods.Ftp.GetDateTimestamp;
    request.UseBinary = true;
    request.UsePassive = true;

    //Line added as hack
    ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateServerCertificate);

    try
    {
        FtpWebResponse response = (FtpWebResponse)request.GetResponse();
    }
    catch (WebException ex)
    {
        FtpWebResponse response = (FtpWebResponse)ex.Response;
        if (response.StatusCode == FtpStatusCode.ActionNotTakenFileUnavailable)
        {
            return false;
        }
    }
    return true;
}

为了忽略证书,我正在使用它:

ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateServerCertificate);

public static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
    System.Diagnostics.Debug.WriteLine(certificate);             
    return true;         
} 

有人可以解释可能导致异常的原因吗?

修改 内部异常显示为: {“收到的邮件意外或格式错误”}

我目前正在使用.Net Franework 4.0 - 问题可能与服务器被限制为TLS 1.2注册的事实有关吗?

0 个答案:

没有答案