Sunday, 15 July 2012

ssl - Is there a way to use FtpWebRequest to authenticate to FTP using client certificates in C#? -


I am trying to upload a file to an FTP server and allow me to authenticate user certificates with the username and No password should be

  var fullFtpPath = String.Concat (ftpItem.FtpAddress, "/", record, ".txt"); FtpWebRequest request = (FtpWebRequest) WebRequest.Create (fullFtpPath); request. Credential = New network credentials (ftpItem.Username, ftpItem.Password); request. Method = WebRequestMethods.Ftp.UploadFile; Request.UseBinary = true; Request.UsePassive = ftpItem.UsePassive; Request.EnableSsl = ftpItem.UseSSL; Request.ContentLength = bytes.Length; (Stream s = request.GetRequestStream ()) using {s.Write (byte, 0, bytes lang); } FtpWebResponse response = (FtpWebResponse) request.GetResponse (); Debug.lightline ("upload file complete, status {0}", response status description); Db.LogExport (siteId, fullFtpPath, record, truth, feedback status description); Response.Close ();  

Above is my current code, but I'm not sure how to implement certification certification or if this is possible. Do I have to make a certificate? Or will the server provide me a certificate and will I set it up in my request?

  • Use certification to specify the certificate to use
  • You create either a certificate of your own (import from a byte array or file), or see it above, a certificate archive ()
< Pre> FtpWebRequest request = (FtpWebRequest) WebRequest.Create ("ftp://ftp.example.com"); request. Credential = new network credentials ("user name", ""); // Query certificate from X509 Store Store = New X509 Store (store name. Mine, store location, current user); Store.Open (OpenFlags.ReadOnly); Const string tp = "2b6f8ac51a85cbaf429474a55304313968667611"; X509Certificate2 cert2 = store.Certificates.Find (X509FindType.FindByThumbprint, TP, True) [0]; Store.Close (); // Add a certificate to the request request. Client Certificate Add (Proof 2);

No comments:

Post a Comment