code: public static void disconnectAndLogoutFromFTPServer(FTPClient ftpClient, String hostName) {
          try {
              // logout and disconnect
              if (ftpClient != null && ftpClient.isConnected()) {
                  ftpClient.logout();
                  ftpClient.disconnect();
              }
          } catch (IOException e) {
              // what the hell?!
              throw new RuntimeException("Unable to logout and disconnect from : " + hostName, e);
          }
      }
docs: Disconnect and logout given FTP client.
  @param hostName the FTP server host name