Skip to content
Snippets Groups Projects
Select Git revision
  • 38c2674e545b29c632119be26df61e86c9730d6d
  • master default protected
  • develop
  • v22w09a
  • v22w08b
  • release
6 results

content.js

Blame
  • FTPClientFactory.java 1.07 KiB
    package fil.sr2.flopbox.utils;
    
    import org.apache.commons.net.ftp.FTPClient;
    import java.io.IOException;
    
    import fil.sr2.flopbox.FTPServerRepository;
    
    public class FTPClientFactory {
    
        public static FTPClient createClient(String alias) throws FTPException {
            FTPServerConfig config = FTPServerRepository.getInstance().getServer(alias);
            if (config == null) {
                throw new FTPException("Serveur FTP non trouvé", 404);
            }
            FTPClient ftpClient = new FTPClient();
            try {
                ftpClient.connect(config.getHost(), config.getPort());
            } catch (IOException e) {
                throw new FTPException("Erreur de connexion FTP: " + e.getMessage(), 500);
            }
            return ftpClient;
        }
    
        public static void disconnect(FTPClient ftpClient) {
            if (ftpClient != null && ftpClient.isConnected()) {
                try {
                    ftpClient.logout();
                    ftpClient.disconnect();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }