FtpExceptions.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using System;
  2. namespace System.Net.FtpClient {
  3. /// <summary>
  4. /// FTP related error
  5. /// </summary>
  6. public class FtpException : Exception {
  7. /// <summary>
  8. /// Initializes the exception object
  9. /// </summary>
  10. /// <param name="message">The error message</param>
  11. public FtpException(string message) : base(message) { }
  12. }
  13. /// <summary>
  14. /// Exception triggered on command failures
  15. /// </summary>
  16. public class FtpCommandException : FtpException {
  17. string _code = null;
  18. /// <summary>
  19. /// Gets the completion code associated with the response
  20. /// </summary>
  21. public string CompletionCode {
  22. get { return _code; }
  23. private set { _code = value; }
  24. }
  25. /// <summary>
  26. /// The type of response received from the last command executed
  27. /// </summary>
  28. public FtpResponseType ResponseType {
  29. get {
  30. if (_code != null) {
  31. // we only care about error types, if an exception
  32. // is being thrown for a successful response there
  33. // is a problem.
  34. switch (_code[0]) {
  35. case '4':
  36. return FtpResponseType.TransientNegativeCompletion;
  37. case '5':
  38. return FtpResponseType.PermanentNegativeCompletion;
  39. }
  40. }
  41. return FtpResponseType.None;
  42. }
  43. }
  44. /// <summary>
  45. /// Initalizes a new instance of a FtpResponseException
  46. /// </summary>
  47. /// <param name="code">Status code</param>
  48. /// <param name="message">Associated message</param>
  49. public FtpCommandException(string code, string message)
  50. : base(message) {
  51. CompletionCode = code;
  52. }
  53. /// <summary>
  54. /// Initalizes a new instance of a FtpResponseException
  55. /// </summary>
  56. /// <param name="reply">The FtpReply to build the exception from</param>
  57. public FtpCommandException(FtpReply reply)
  58. : this(reply.Code, reply.ErrorMessage) {
  59. }
  60. }
  61. /// <summary>
  62. /// Exception is thrown when encryption could not be negotiated by the server
  63. /// </summary>
  64. public class FtpSecurityNotAvailableException : FtpException {
  65. /// <summary>
  66. /// Default constructor
  67. /// </summary>
  68. public FtpSecurityNotAvailableException()
  69. : base("Security is not available on the server.") {
  70. }
  71. /// <summary>
  72. /// Custom error message
  73. /// </summary>
  74. /// <param name="message">Error message</param>
  75. public FtpSecurityNotAvailableException(string message)
  76. : base(message) {
  77. }
  78. }
  79. }