Skip to content
Snippets Groups Projects
Select Git revision
  • 0db33b3e0d937ab618921fc235545baeabfe093d
  • main default protected
  • version_pour_projet_2
  • dev
  • LIVRABLE_3
  • LIVRABLE_2
  • LIVRABLE_1
7 results

FTPClientFactory.java

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();
                }
            }
        }
    }