code: public static void connectAndLoginOnFTPServer(FTPClient ftpClient,
              String hostName, Integer port, String userName, String password) {
          try {
              if (port != null && port.intValue() > 0) {
                  ftpClient.connect(hostName, port);
              } else {
                  ftpClient.connect(hostName);
              }
              if (!FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) {
                  throw new IOException(String.format("FTP server '%s' refused connection.", hostName));
              }
  
              // try to login
              if (!ftpClient.login(userName, password)) {
                  throw new IOException(String.format("Unable to login to FTP server '%s'.", hostName));
              }
          } catch (IOException ex) {
              throw new RuntimeException(
                      String.format("Unable to connect and login to FTP server '%s'. Cause: ", hostName), ex);
          }
      }
docs: Connect and login on given FTP server with provided credentials.
  @param hostName the FTP server host name to connect
  @param port the port to connect
  @param userName the user name
  @param password the password