Package de.bytestore.hostinger.handler
Class FTPService
java.lang.Object
de.bytestore.hostinger.handler.FTPService
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
FieldsModifier and TypeFieldDescriptionintintintint -
Constructor Summary
ConstructorsConstructorDescriptionFTPService(GuardianService guardianService, io.jmix.core.security.SystemAuthenticator systemAuthenticator) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAccount(String usernameIO, String passwordIO, File homeIO) Adds a new FTP account with the specified username, password, and home directory.booleanexistsAccount(String usernameIO) Checks if an FTP account with the specified username exists.voidload()Loads FTP server settings from the provided AppSettings instance and configures server port and speed limitations.voidonApplicationStarted(org.springframework.boot.context.event.ApplicationStartedEvent event) voidremoveAccount(String usernameIO) Removes an FTP account with the specified username.voidstart()Initializes and starts the FTP server with the specified configuration.
-
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
RuntimeExceptionis 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 anFtpException. -
addAccount
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
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
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.
-