使用ftp4j时我有这个问题:
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
FTP服务器已启用端口22上的连接,我可以连接没有问题filezilla。
这是我的代码:
private boolean copiarArchviosFtp(){ FTPClient ftpDestino=new FTPClient(); try{ TrustManager[] trustManager = new TrustManager[] { new X509TrustManager() { public X509Certificate[] getAcceptedIssuers() { return null; } public void checkClientTrusted(X509Certificate[] certs, String authType) { } public void checkServerTrusted(X509Certificate[] certs, String authType) { } } }; SSLContext sslContext = null; try { sslContext = SSLContext.getInstance("SSL"); sslContext.init(null, trustManager, new SecureRandom()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (KeyManagementException e) { e.printStackTrace(); } SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory(); ftpDestino.setSSLSocketFactory(sslSocketFactory); ftpDestino.setSecurity(FTPClient.SECURITY_FTPS); ftpDestino.connect("172.24.1.109",22); ftpDestino.login("user","password"); ftpDestino.changeDirectory("/home/"); FTPFile[] listFilte=ftpDestino.list(); for(FTPFile ftpFile:listFilte){ System.out.println("nameFile: "+ftpFile.getName()); } } catch(Exception e){ // TODO Auto-generated catch block e.printStackTrace(); } return false; }
任何想法如何解决这个问题?
我正在调查如何通过SFTP复制文件。 即使指定了FTPClient.SECURITY_FTPS,ftp4j库也不能正常工作,因为FTPS与SFTP不同。
我找到了一个使用另一个库JSCH的解决方案。
这是一个JSCH的例子。 我希望这有助于某人。
这里是关于SFTP vs FTPS的 更多信息 。