I open the connection to the FTP server at the beginning of my program.
Before performing operations on the server, I want to check whether the connection was successfully established. The simplest quick manner, so if the connection is gone, I will try to connect again.
I used this code for this:
private boolean checkConnection() { try { boolean success = ftpClient.login(user_name, password); if(success) return true; else return false; } }
But this method throws a NullPointer exception when the connection has been closed.
I can check the connection with ftpClient.connect(server, port); but it is like trying to connect again and again.
What is the way to test the connection?
source share