title: Exception thrown when trying connect with FTPS using FtpWebRequest c#" - A call to SSPI failed, see inner exception"
body: <p>I'm trying to update some FTP code I have as the server I'm connecting to is now forcing FTPS.</p>
  
  <p>The exception I'm getting is as follows : </p>
  
  <blockquote>
    <p>Message=A call to SSPI failed, see inner exception.</p>
  </blockquote>
  
  <p>The code I'm using to connect is as follows:</p>
  
  <pre><code>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;
  }
  </code></pre>
  
  <p>In order to ignore the cert, I'm using this:</p>
  
  <pre><code>ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateServerCertificate);
  
  public static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
  {
      System.Diagnostics.Debug.WriteLine(certificate);             
      return true;         
  } 
  </code></pre>
  
  <p>Could someone explain what might be causing the exception?</p>
  
  <p><strong>Edit:</strong>
  The inner exception is showing as:
  {"The message received was unexpected or badly formatted"}</p>
  
  <p>I'm currently using the .Net Franework 4.0 - could the problem be releated to the fact the server has been restricted to TLS 1.2 encription?</p>