Ejemplo n.º 1
0
        internal FtpClient GetClient(IOConnectionInfo ioc, bool enableCloneClient = true)
        {
            var settings = ConnectionSettings.FromIoc(ioc);

            FtpClient client = new RetryConnectFtpClient();

            if ((settings.Username.Length > 0) || (settings.Password.Length > 0))
            {
                client.Credentials = new NetworkCredential(settings.Username, settings.Password);
            }
            else
            {
                client.Credentials = new NetworkCredential("anonymous", "");                 //TODO TEST
            }
            Uri uri = IocToUri(ioc);

            client.Host = uri.Host;
            if (!uri.IsDefaultPort)             //TODO test
            {
                client.Port = uri.Port;
            }

            client.ValidateCertificate += (control, args) =>
            {
                args.Accept = _app.CertificateValidationCallback(control, args.Certificate, args.Chain, args.PolicyErrors);
            };

            client.EncryptionMode = settings.EncryptionMode;

            client.Connect();
            return(client);
        }
Ejemplo n.º 2
0
            protected override FtpClient CloneConnection()
            {
                RetryConnectFtpClient conn = new RetryConnectFtpClient();

                conn.m_isClone = true;

                foreach (PropertyInfo prop in GetType().GetProperties())
                {
                    object[] attributes = prop.GetCustomAttributes(typeof(FtpControlConnectionClone), true);

                    if (attributes != null && attributes.Length > 0)
                    {
                        prop.SetValue(conn, prop.GetValue(this, null), null);
                    }
                }

                // always accept certficate no matter what because if code execution ever
                // gets here it means the certificate on the control connection object being
                // cloned was already accepted.
                conn.ValidateCertificate += new FtpSslValidation(
                    delegate(FtpClient obj, FtpSslValidationEventArgs e)
                {
                    e.Accept = true;
                });

                return(conn);
            }