Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
2.2k views
in Java FTP by (160 points)
I am having Windows 8.1, with FTP server running on IIS server. I have created a self signed certificate on IIS, and trying to connect it with FileZilla. For the first time it asks to trust the certificate or not, on trusting self signed certificate it establishes the connection.

I am trying to do same thing with enterpriseDT API. But it gives following stacktrace.
com.enterprisedt.net.ftp.ssl.SSLFTPCertificateException: Server certificate could not be validated. (use SSLFTPCertificateException.printCertificates to view certificates.)
        at com.enterprisedt.net.ftp.ssl.SSLFTPControlSocket.c(SSLFTPControlSocket.java:326)
        at com.enterprisedt.net.ftp.ssl.SSLFTPClient.auth(SSLFTPClient.java:1457)
        at UseFTPSWithoutServerValidation.main(UseFTPSWithoutServerValidation.java:69)


This exception is thrown when auth method is called. I am trying to establish FTPS-External connection.

Any guesses why it is working with FileZilla and not as an individual Java program?

2 Answers

0 votes
by (162k points)
You need to do what Filezilla does - save a copy of the certificate and load it. There's a method for obtaining the certificate from the server, and another to load it explicitly.
0 votes
by (160 points)
Thanks for the help.

I have tried that way and it works. Here is the code snippet, it will be helpful if anyone have similar issue.

SSLFTPClient ftp = new SSLFTPClient();

SSLFTPCertificate certificate = ftp.getServerCertificate(host);

File pemFile = new File("my_cert.pem");
FileOutputStream pemFileOutputStream = new FileOutputStream(pemFile);

try {
    certificate.writePEM(pemFileOutputStream);

    ftp.getRootCertificateStore().importPEMFile(pemFile.getAbsolutePath());
} catch (Exception ex) {
} finally {
    try {
        pemFileOutputStream.close();
    } catch (Exception ex) {
    }
}

ftp.connect();

ftp.auth(SSLFTPClient.AUTH_TLS);

Categories

...