I am looking for Java sample code to connect to FTP server using SSL certificate. I have all needed certificates in my project folder. I tried some approach, but it doesnt work. We are using Spring batch component. Any help is appreciated. Thanks
protected FTPSClient createFTPClient() throws Exception {
FTPSClient client = new FTPSClient(protocol,true);
client.setNeedClientAuth(true);
KeyStore ks = KeyStore.getInstance("JKS");
FileInputStream fis = new FileInputStream(keyStoreFile);
ks.load(fis, keyStorePassword.toCharArray());
fis.close();
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory .getDefaultAlgorithm());
kmf.init(ks, keyStorePassword.toCharArray());
client.setKeyManager(kmf.getKeyManagers()[0]);
return client;
}
int reply;
FTPSClient ftps = null;
try {
ftps = createFTPClient();
ftps.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
//ftps.setTrustManager(trustManager)
ftps.connect(host,portnumber);
......
I am getting Plaintext connection exception....
I got this from this different question 425 error ftp over SSL in Java
ftps.setTrustManager(TrustManagerUtils.getAcceptAllTrustManager());
It might help.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.