using System;
using System.Net.Security;
using Limilabs.FTP.Client;

namespace OverSSL
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            using (Ftp client = new Ftp())
            {
                // Use this line to validate self-signed certificates:
                client.ServerCertificateValidate += ValidateCertificate;

                client.ConnectSSL("ftp.example.org");
                client.Login("username", "password");

                foreach (FtpItem item in client.GetList())
                {
                    if (item.IsFolder == true)
                    {
                        Console.WriteLine("[{0}]", item.Name);
                    }
                    else
                    {
                        Console.WriteLine("{0}", item.Name);
                    }
                }
                client.Close();
            }
            Console.ReadKey();
        }

        private static void ValidateCertificate(object sender, ServerCertificateValidateEventArgs e)
        {
            const SslPolicyErrors ignoredErrors =
                SslPolicyErrors.RemoteCertificateChainErrors |
                SslPolicyErrors.RemoteCertificateNameMismatch;

            if ((e.SslPolicyErrors & ignoredErrors) != 0)
            {
                e.IsValid = true;
                return;
            }
            e.IsValid = false;
        }
    } ;
}
