Java 如何通过sftp连接到linux使用ftp4j
我在使用ftp4j时遇到以下问题:Java 如何通过sftp连接到linux使用ftp4j,java,linux,ssl,ftp,Java,Linux,Ssl,Ftp,我在使用ftp4j时遇到以下问题: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection? ftp服务器在端口22上启用了连接,我可以毫无问题地连接filezilla 这是我的代码: private boolean copiarArchviosFtp(){ FTPClient ftpDestino=new FTPClient(); try{ TrustManag
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复制文件。ftp4j库即使在指定了FTPClient.SECURITY_FTPS的情况下也无法工作,因为FTPS与SFTP不同 我使用另一个名为JSCH的库找到了一个解决方案 下面是一个例子。我希望这对某人有帮助 现在开始