title: Java code to connect to FTP server using SSL
body: <p>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</p>
  
  <pre><code>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);
    ......
  </code></pre>
  
  <p>I am getting Plaintext connection exception....</p>