using System; namespace System.Net.FtpClient { /// /// FTP related error /// public class FtpException : Exception { /// /// Initializes the exception object /// /// The error message public FtpException(string message) : base(message) { } } /// /// Exception triggered on command failures /// public class FtpCommandException : FtpException { string _code = null; /// /// Gets the completion code associated with the response /// public string CompletionCode { get { return _code; } private set { _code = value; } } /// /// The type of response received from the last command executed /// public FtpResponseType ResponseType { get { if (_code != null) { // we only care about error types, if an exception // is being thrown for a successful response there // is a problem. switch (_code[0]) { case '4': return FtpResponseType.TransientNegativeCompletion; case '5': return FtpResponseType.PermanentNegativeCompletion; } } return FtpResponseType.None; } } /// /// Initalizes a new instance of a FtpResponseException /// /// Status code /// Associated message public FtpCommandException(string code, string message) : base(message) { CompletionCode = code; } /// /// Initalizes a new instance of a FtpResponseException /// /// The FtpReply to build the exception from public FtpCommandException(FtpReply reply) : this(reply.Code, reply.ErrorMessage) { } } /// /// Exception is thrown when encryption could not be negotiated by the server /// public class FtpSecurityNotAvailableException : FtpException { /// /// Default constructor /// public FtpSecurityNotAvailableException() : base("Security is not available on the server.") { } /// /// Custom error message /// /// Error message public FtpSecurityNotAvailableException(string message) : base(message) { } } }