Class FTPService

java.lang.Object
de.bytestore.hostinger.handler.FTPService

@Component @Service public class FTPService extends Object
Service for managing an internal FTP server, including account management and server configuration. This service provides methods for starting the server, adding or removing FTP accounts, loading configuration settings, and checking for the existence of user accounts. The FTP server is configured
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    int
     
    int
     
    int
     
    int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    FTPService(GuardianService guardianService, io.jmix.core.security.SystemAuthenticator systemAuthenticator)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addAccount(String usernameIO, String passwordIO, File homeIO)
    Adds a new FTP account with the specified username, password, and home directory.
    boolean
    existsAccount(String usernameIO)
    Checks if an FTP account with the specified username exists.
    void
    Loads FTP server settings from the provided AppSettings instance and configures server port and speed limitations.
    void
    onApplicationStarted(org.springframework.boot.context.event.ApplicationStartedEvent event)
     
    void
    removeAccount(String usernameIO)
    Removes an FTP account with the specified username.
    void
    Initializes and starts the FTP server with the specified configuration.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • portIO

      public int portIO
    • defaultUpload

      public int defaultUpload
    • defaultDownload

      public int defaultDownload
    • defaultIdleTime

      public int defaultIdleTime
  • Constructor Details

    • FTPService

      public FTPService(GuardianService guardianService, io.jmix.core.security.SystemAuthenticator systemAuthenticator)
  • Method Details

    • onApplicationStarted

      @EventListener public void onApplicationStarted(org.springframework.boot.context.event.ApplicationStartedEvent event)
    • start

      public void start()
      Initializes and starts the FTP server with the specified configuration. The method performs the following operations:
        - Configures the server port using the provided settings. - If secure mode is enabled, ensures that the necessary keystore and truststore files exist, and applies SSL configurations such as keystore and truststore paths and their respective passwords. - Logs errors and updates the system monitoring service if required files for secure mode are missing. - Adds a default listener to the server. - Creates and starts the FTP server instance. - Logs a debug message to confirm that the server has started on the appropriate port. If the server fails to start due to an underlying exception, a RuntimeException is thrown. Preconditions: - The necessary settings for port configuration and secure mode must be correctly populated. - Keystore and truststore files must be available in the specified paths if secure mode is enabled. Postconditions: - The internal FTP server is started and ready to handle requests. Throws: - RuntimeException if the server fails to start due to an FtpException.
    • addAccount

      public void addAccount(String usernameIO, String passwordIO, File homeIO)
      Adds a new FTP account with the specified username, password, and home directory. It assigns write permissions and sets default transfer rate limitations for the new account.
      Parameters:
      usernameIO - The username for the new FTP account.
      passwordIO - The password for the new FTP account.
      homeIO - The home directory for the new FTP account.
    • removeAccount

      public void removeAccount(String usernameIO)
      Removes an FTP account with the specified username.
      Parameters:
      usernameIO - The username of the FTP account to be removed.
      Throws:
      RuntimeException - if an error occurs while deleting the user.
    • load

      public void load()
      Loads FTP server settings from the provided AppSettings instance and configures server port and speed limitations.
    • existsAccount

      public boolean existsAccount(String usernameIO)
      Checks if an FTP account with the specified username exists.
      Parameters:
      usernameIO - The username of the FTP account to check existence for.
      Returns:
      true if the FTP account exists, false otherwise.
      Throws:
      RuntimeException - if an error occurs while checking existence.