Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
3.7k views
in FAQ: edtFTPnet/PRO by (162k points)
closed by
How to download using HTTPS?
closed with the note: Answered

1 Answer

0 votes
by (20.4k points)
 
Best answer

To download using HTTPS, the machine needs to have the HTTPS certificate in its trusted store. If it is not (e.g. it is a self signed certificate), you will get an error like "Could not establish trust relationship for the SSL/TLS secure channel".

Currently, to deal with this the certificate needs to be imported into the trusted store, or validation needs to be bypassed.

This can be done as follows, using the ServerCertificateValidationCallback.
 

using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;

ServicePointManager.ServerCertificateValidationCallback
                += new RemoteCertificateValidationCallback(BypassSslCertificateValidation);

ftpConnection.Protocol = FileTransferProtocol.HTTP;
ftpConnection.UserName = "javaftp";
ftpConnection.Password = "javaftp";
ftpConnection.ServerAddress = "https://myurl";
ftpConnection.Connect();
ftpConnection.DownloadFile("d:\\tmp\\myfile.pdf", "https://myurl/myfile.pdf");

private static bool BypassSslCertificateValidation(
     object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors error)
{
      return true;
}
...