How to connect to FTP through a TLS / SSL (FTPS) server in Java

I am stuck in connecting to FTP through a TLS / SSL server (FTPS). I use SimpleFTP library through, I can connect to an FTP server without SSL, but I can not connect FTPS.

This gives me this error on line 2 (ftp.connect),

SimpleFTP received an unknown response when connecting to an FTP server:
220 ---------- Welcome to Pure-FTPd [privsep] [TLS] ----------

and i use below code

SimpleFTP ftp = new SimpleFTP(); // Connect to an FTP server on port 21. ftp.connect("xxx.xxx.xxx.xxx", 21, "username", "pwd"); //getting error at (ftp.connect) above line // Set binary mode. ftp.bin(); // Change to a new working directory on the FTP server. ftp.cwd("web"); ftp.disconnect(); 
+8
source share
1 answer

Class / Library SimpleFTP does not support TLS / SSL.


Instead, use the FTPSClient class from the Apache Commons Net library .

See the official example for the FTPClient class and simply replace FTPClient with FTPSClient .

 FTPSClient ftpClient = new FTPSClient(); ftpClient.connect(host); ftpClient.login(user, password); 

The FTPSClient class uses explicit TLS / SSL by default (recommended). In rare cases, you need implicit TLS / SSL, use new FTPSClient(true) .

+22
source

Source: https://habr.com/ru/post/1246048/


All Articles