我在使用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;
}有关于如何解决这个问题的想法吗?
发布于 2012-12-06 09:29:36
我正在研究如何通过SFTP复制文件。即使使用指定的FTPClient.SECURITY_FTPS,ftp4j库也不起作用,因为FTPS与SFTP不同。
我找到了一个使用另一个名为JSCH的库的解决方案。
以下是JSCH的一个示例。我希望这对某些人有帮助。
这是SFTP vs FTPS上的more information。
https://stackoverflow.com/questions/13495969
复制相似问题