Select Git revision
FTPClientFactory.java
-
fabiovandewaeter authoredfabiovandewaeter authored
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();
}
}
}
}