using System; #if !CORE using System.Runtime.Serialization; #endif namespace FluentFTP { /// /// FTP related error /// #if !CORE [Serializable] #endif public class FtpException : Exception { /// /// Initializes the exception object /// /// The error message public FtpException(string message) : base(message) { } /// /// Initializes the exception object /// public FtpException(string message, Exception innerException) : base(message, innerException) { } #if !CORE /// /// Must be implemented so every Serializer can Deserialize the Exception /// protected FtpException(SerializationInfo info, StreamingContext context) : base(info, context) { } #endif } /// /// Exception triggered on command failures /// #if !CORE [Serializable] #endif 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) { } #if !CORE /// /// Must be implemented so every Serializer can Deserialize the Exception /// protected FtpCommandException(SerializationInfo info, StreamingContext context) : base(info, context) { } #endif } /// /// Exception is thrown when encryption could not be negotiated by the server /// #if !CORE [Serializable] #endif 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) { } #if !CORE /// /// Must be implemented so every Serializer can Deserialize the Exception /// protected FtpSecurityNotAvailableException(SerializationInfo info, StreamingContext context) : base(info, context) { } #endif } }