我正在寻找使用 SSL 证书连接到 FTP 服务器的 Java 示例代码。我的项目文件夹中有所有需要的证书。我尝试了一些方法,但它不起作用。我们正在使用 Spring 批处理组件。任何帮助表示赞赏。谢谢
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);
......
我收到明文连接异常....