Esempio n. 1
0
 /// <summary>
 /// Fire the invalid SSL certificate event
 /// </summary>
 public void OnInvalidSslCerticate(FtpChannel c, InvalidCertificateInfo e)
 {
     if (this._onBadCert != null)
     {
         this._onBadCert(c, e);
     }
 }
        /// <summary>
        /// Upon the initial connection, we will be presented with a banner and status
        /// </summary>
        void OnChannelConnected(FtpChannel c)
        {
            if (this.SslMode == FtpSslMode.Implicit)
            {
                // The connection should already be encrypted
                // so authenticate the connection and then
                // try to read the initial greeting.
                this.AuthenticateConnection();
            }


            if (!this.ReadResponse())
            {
                this.Disconnect();
                throw new FtpCommandException(this);
            }

            if (this.SslMode == FtpSslMode.Explicit)
            {
                if (this.Execute("AUTH TLS") || this.Execute("AUTH SSL"))
                {
                    this.AuthenticateConnection();
                }
                else if (this._secNotAvailable != null)
                {
                    FtpSecurityNotAvailable secna = new FtpSecurityNotAvailable(this);

                    this._secNotAvailable(secna);

                    if (secna.Cancel)
                    {
                        throw new FtpCommandException(this);
                    }
                }
            }

            if (this.SslEnabled && this.DataChannelEncryption)
            {
                if (!this.Execute("PBSZ 0"))
                {
                    // do nothing? some severs don't even
                    // care if you execute PBSZ however rfc 4217
                    // says that PBSZ is required if you want
                    // data channel security.
                    //throw new FtpCommandException(this);
#if DEBUG
                    System.Diagnostics.Debug.WriteLine("PBSZ ERROR: " + this.ResponseMessage);
#endif
                }

                if (!this.Execute("PROT P"))   // turn on data channel protection.
                {
                    throw new FtpCommandException(this);
                }
            }

            this.Capabilities = FtpCapability.EMPTY;
        }
		/// <summary>
		/// Iniatlizes the object
		/// </summary>
		/// <param name="c">The ftp channel this object is associated with. Could
		/// be FtpControlConnection or FtpDataChannel</param>
		public InvalidCertificateInfo(FtpChannel c) {
			this.SslPolicyErrors = c.SslPolicyErrors;
			this.SslCertificate = c.SslCertificate;
		}
Esempio n. 4
0
 void OnInvalidCertficate(FtpChannel c, InvalidCertificateInfo e)
 {
     // we don't care if a certificate is invalid
     e.Ignore = true;
 }
Esempio n. 5
0
 /// <summary>
 /// Iniatlizes the object
 /// </summary>
 /// <param name="c">The ftp channel this object is associated with. Could
 /// be FtpControlConnection or FtpDataChannel</param>
 public InvalidCertificateInfo(FtpChannel c)
 {
     this.SslPolicyErrors = c.SslPolicyErrors;
     this.SslCertificate  = c.SslCertificate;
 }
Esempio n. 6
0
        /// <summary>
        /// This is the ConnectionReady event handler. It performs the FTP login
        /// if a connection to the server has been made.
        /// </summary>
        void Login(FtpChannel c) {
            this.LockControlConnection();

            try {
                if (this.Username != null) {
                    // there's no reason to pipeline here if the password is null
                    if (this.EnablePipelining && this.Password != null) {
                        FtpCommandResult[] res = this.Execute(new string[] {
							string.Format("USER {0}", this.Username),
							string.Format("PASS {0}", this.Password)
						});

                        foreach (FtpCommandResult r in res) {
                            if (!r.ResponseStatus) {
                                throw new FtpCommandException(r.ResponseCode, r.ResponseMessage);
                            }
                        }
                    }
                    else {
                        if (!this.Execute("USER {0}", this.Username)) {
                            throw new FtpCommandException(this);
                        }

                        if (this.ResponseType == FtpResponseType.PositiveIntermediate) {
                            if (this.Password == null) {
                                throw new FtpException("The server is asking for a password but it has been set.");
                            }

                            if (!this.Execute("PASS {0}", this.Password)) {
                                throw new FtpCommandException(this);
                            }
                        }
                    }
                }
            }
            finally {
                this.UnlockControlConnection();
            }
        }
Esempio n. 7
0
		/// <summary>
		/// Fire the invalid SSL certificate event
		/// </summary>
		public void OnInvalidSslCerticate(FtpChannel c, InvalidCertificateInfo e) {
			if (this._onBadCert != null) {
				this._onBadCert(c, e);
			}
		}
        /// <summary>
        /// Upon the initial connection, we will be presented with a banner and status
        /// </summary>
        void OnChannelConnected(FtpChannel c) {
            if (this.SslMode == FtpSslMode.Implicit) {
                // The connection should already be encrypted
                // so authenticate the connection and then
                // try to read the initial greeting.
                this.AuthenticateConnection();
            }


            if (!this.ReadResponse()) {
                this.Disconnect();
                throw new FtpCommandException(this);
            }

            if (this.SslMode == FtpSslMode.Explicit) {
                if (this.Execute("AUTH TLS") || this.Execute("AUTH SSL")) {
                    this.AuthenticateConnection();
                }
                else if (this._secNotAvailable != null) {
                    FtpSecurityNotAvailable secna = new FtpSecurityNotAvailable(this);

                    this._secNotAvailable(secna);

                    if (secna.Cancel) {
                        throw new FtpCommandException(this);
                    }
                }
            }

            if (this.SslEnabled && this.DataChannelEncryption) {
                if (!this.Execute("PBSZ 0")) {
                    // do nothing? some severs don't even
                    // care if you execute PBSZ however rfc 4217
                    // says that PBSZ is required if you want
                    // data channel security.
                    //throw new FtpCommandException(this);
#if DEBUG
                    System.Diagnostics.Debug.WriteLine("PBSZ ERROR: " + this.ResponseMessage);
#endif
                }

                if (!this.Execute("PROT P")) { // turn on data channel protection.
                    throw new FtpCommandException(this);
                }
            }

            this.Capabilities = FtpCapability.EMPTY;
        }