using System;
using System.IO;
using Chilkat;

// Factory arayüzü
interface IFileDownloaderFactory
{
    IFileDownloader CreateFileDownloader();
}

// FTP için Factory sınıfı
class FTPFileDownloaderFactory : IFileDownloaderFactory
{
    public IFileDownloader CreateFileDownloader()
    {
        return new FTPFileDownloader();
    }
}

// FTPS için Factory sınıfı
class FTPSFileDownloaderFactory : IFileDownloaderFactory
{
    public IFileDownloader CreateFileDownloader()
    {
        return new FTPSFileDownloader();
    }
}

// Dosya indirme arayüzü
interface IFileDownloader
{
    void DownloadFile(string host, int port, string username, string password, string filePath, MemoryStream stream);
}

// FTP için dosya indirme sınıfı
class FTPFileDownloader : IFileDownloader
{
    public void DownloadFile(string host, int port, string username, string password, string filePath, MemoryStream stream)
    {
        Ftp2 ftp = new Ftp2();
        ftp.Connect(host, port);
        ftp.Login(username, password);
        ftp.GetFile(filePath, stream);
        ftp.Disconnect();
    }
}

// FTPS için dosya indirme sınıfı
class FTPSFileDownloader : IFileDownloader
{
    public void DownloadFile(string host, int port, string username, string password, string filePath, MemoryStream stream)
    {
        Ftp2 ftp = new Ftp2();
        ftp.Ssl = true;
        ftp.OnSslServerCert += new Ftp2.OnSslServerCertEventHandler(ValidateCertificate);
        ftp.Connect(host, port);
        ftp.AuthTls();
        ftp.Login(username, password);
        ftp.GetFile(filePath, stream);
        ftp.Disconnect();
    }

    // SSL sertifikası doğrulama olayı
    static void ValidateCertificate(object sender, FtpCertInfo cert)
    {
        // Sertifika doğrulama kodunu buraya ekleyin
        // Örneğin, sertifika doğrulama sürecini kontrol ederek e.Accept'e true veya false atayabilirsiniz
    }
}

class Program
{
    static void Main(string[] args)
    {
        // FTP sunucu bilgileri
        string ftpHost = "ftp.example.com";
        int ftpPort = 21;
        string ftpUsername = "your_ftp_username";
        string ftpPassword = "your_ftp_password";
        string ftpFilePath = "/path/to/your/excel/file.xlsx";

        // FTPS sunucu bilgileri
        string ftpsHost = "ftps.example.com";
        int ftpsPort = 990;
        string ftpsUsername = "your_ftps_username";
        string ftpsPassword = "your_ftps_password";
        string ftpsFilePath = "/path/to/your/excel/file.xlsx";

        // Factory sınıfları oluştur
        IFileDownloaderFactory ftpFactory = new FTPFileDownloaderFactory();
        IFileDownloaderFactory ftpsFactory = new FTPSFileDownloaderFactory();

        // FTP üzerinden dosya indirme işlemi
        IFileDownloader ftpDownloader = ftpFactory.CreateFileDownloader();
        MemoryStream ftpStream = new MemoryStream();
        ftpDownloader.DownloadFile(ftpHost, ftpPort, ftpUsername, ftpPassword, ftpFilePath, ftpStream);

        // FTPS üzerinden dosya indirme işlemi
        IFileDownloader ftpsDownloader = ftpsFactory.CreateFileDownloader();
        MemoryStream ftpsStream = new MemoryStream();
        ftpsDownloader.DownloadFile(ftpsHost, ftpsPort, ftpsUsername, ftpsPassword, ftpsFilePath, ftpsStream);

        // MemoryStream'deki veriyi kullanarak Excel dosyasını okuyabilirsiniz
    }
}