dev-resources.site
for different kinds of informations.
Java FTPS disabling Certificate Check , FOR FIX FTP SSL certificate expired exception
Published at
3/26/2024
Categories
java
sftp
Author
Teddy Zugana
1)the encryption of the FTPS server will be either TLS explicit encryption or TLS explicit encryption.Use the constructor arg for FTPS accordingly. like
FTPSClient ftpClient = new FTPSClient(false);
2)if your FTPS server security certificate has expired, disable the check from client by
ftpClient.setTrustManager(new X509TrustManager() {
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
@Override
public void checkClientTrusted(X509Certificate[] certs, String authType) {
}
@Override
public void checkServerTrusted(X509Certificate[] certs, String authType) {
}
});
3)enable file transfer between server and client using this method
ftpClient.enterLocalPassiveMode();
4)use the right port number. Usually for explicit encryption it is 21 and for implicit it is 990
The above four are the common configs required to establish a connection. The end snippet looks something like this
FTPSClient ftpClient = new FTPSClient(false);
ftpClient.setTrustManager(new X509TrustManager() {
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
@Override
public void checkClientTrusted(X509Certificate[] certs, String authType) {
}
@Override
public void checkServerTrusted(X509Certificate[] certs, String authType) {
}
});
ftpClient.connect("ftps.mydomain.com",21);
boolean res = ftpClient.login("username", "password");
if(!res) throw new Exception("unable to connect to ftps");
int reply=ftpClient.getReplyCode();
if(FTPReply.isPositiveCompletion(reply)){
ftpClient.enterLocalPassiveMode();
FTPFile[] ftpFiles = ftpClient.listFiles("/folder/subfolder");
System.out.println("complete "+reply+" "+ftpFiles.length);
for(FTPFile x: ftpFiles){
System.out.println(x.getName());
}
ftpClient.retrieveFile("/folder/subfolder/file.tsv",new FileOutputStream(new File("C:\\Users\\myname\\Desktop\\out.csv")));
}else{
throw new RuntimeException("unable to get valid reply from ftp server. Reply code is "+reply);
}
Articles
12 articles in total
Obfuscating “Hello world!” obfuscate on Python
read article
Secure Nginx with Let's Encrypt on Ubuntu
read article
Auto Deploy Laravel with Deployer.yml sample With Github Runner
read article
Managing Docker Containers with Portainer
read article
Nginx force http to https On 443 https Port
read article
Java FTPS disabling Certificate Check , FOR FIX FTP SSL certificate expired exception
currently reading
GIS MAP Leaflet JS with OPENSTREETMAP SAMPLE
read article
GIS MAP Leaflet JS with API MAPBOX SAMPLE
read article
Jaro and Jaro-Winkler distance, measuring similarity between strings on PHP.
read article
Python Scraping web page with BeautifulSoup and requests Example
read article
PHP Mimic Excel Rate Function
read article
How To Install unixODBC-devel on CentOS 7 and Connect DB2 V9.7
read article
Featured ones: