code: public static String loadFileFromFTPServer(String hostName, Integer port,
              String userName, String password, String filePath, int numberOfLines) {
  
          String result = null;
          FTPClient ftpClient = new FTPClient();
          InputStream inputStream = null;
          String errorMessage = "Unable to connect and download file '%s' from FTP server '%s'.";
  
          try {
              connectAndLoginOnFTPServer(ftpClient, hostName, port, userName, password);
  
              // load file into string
              ftpClient.enterLocalPassiveMode();
              inputStream = ftpClient.retrieveFileStream(filePath);
              validatResponse(ftpClient);
              result = FileUtil.streamToString(inputStream, filePath, numberOfLines);
              ftpClient.completePendingCommand();
  
          } catch (IOException ex) {
              throw new RuntimeException(String.format(errorMessage, filePath, hostName), ex);
  
          } finally {
              closeInputStream(inputStream);
              disconnectAndLogoutFromFTPServer(ftpClient, hostName);
          }
  
          return result;
      }
docs: Reads content of file on from FTP server to String.
  @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 filePath file to read.
  @return file's content.
  @throws RuntimeException in case any exception has been thrown.