code: public static String executeCommandOnFTPServer(String hostName, Integer port,
              String userName, String password, String command, String commandArgs) {
          String result = null;
  
          if (StringUtils.isNotBlank(command)) {
              FTPClient ftpClient = new FTPClient();
              String errorMessage = "Unable to connect and execute %s command with argumments '%s' for FTP server '%s'.";
  
              try {
                  connectAndLoginOnFTPServer(ftpClient, hostName, port, userName, password);
                  // execute command
                  if (StringUtils.isBlank(commandArgs)) {
                      ftpClient.sendCommand(command);
                  } else {
                      ftpClient.sendCommand(command, commandArgs);
                  }
  
                  validatResponse(ftpClient);
                  result = ftpClient.getReplyString();
  
              } catch (IOException ex) {
                  throw new RuntimeException(String.format(errorMessage, command, commandArgs, hostName), ex);
              } finally {
                  disconnectAndLogoutFromFTPServer(ftpClient, hostName);
              }
          }
          return result;
      }
docs: Execute command with supplied arguments on the FTP server.
  @param hostName the FTP server host name to connect
  @param port the port to connect
  @param userName the user name
  @param password the password
  @param command the command to execute.
  @param commandArgs the command argument(s), if any.
  @return reply string from FTP server after the command has been executed.
  @throws RuntimeException in case any exception has been thrown.