2
0

FtpWebResponse.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. //
  2. // System.Net.FtpWebResponse.cs
  3. //
  4. // Authors:
  5. // Carlos Alberto Cortez ([email protected])
  6. //
  7. // (c) Copyright 2006 Novell, Inc. (http://www.novell.com)
  8. //
  9. using System;
  10. using System.IO;
  11. using System.Runtime.Serialization;
  12. #if NET_2_0
  13. namespace System.Net
  14. {
  15. public class FtpWebResponse : WebResponse
  16. {
  17. Stream stream = Stream.Null;
  18. Uri uri;
  19. FtpStatusCode statusCode;
  20. DateTime lastModified = DateTime.MinValue;
  21. string bannerMessage = String.Empty;
  22. string welcomeMessage = String.Empty;
  23. string exitMessage = String.Empty;
  24. string statusDescription;
  25. string method;
  26. //bool keepAlive;
  27. bool disposed;
  28. internal long contentLength = -1;
  29. internal FtpWebResponse (Uri uri, string method, bool keepAlive)
  30. {
  31. this.uri = uri;
  32. this.method = method;
  33. //this.keepAlive = keepAlive;
  34. }
  35. public override long ContentLength {
  36. get {
  37. return contentLength;
  38. }
  39. }
  40. public override WebHeaderCollection Headers {
  41. get {
  42. return new WebHeaderCollection (true);
  43. }
  44. }
  45. public override Uri ResponseUri {
  46. get {
  47. return uri;
  48. }
  49. }
  50. public DateTime LastModified {
  51. get {
  52. return lastModified;
  53. }
  54. internal set {
  55. lastModified = value;
  56. }
  57. }
  58. public string BannerMessage {
  59. get {
  60. return bannerMessage;
  61. }
  62. internal set {
  63. bannerMessage = value;
  64. }
  65. }
  66. public string WelcomeMessage {
  67. get {
  68. return welcomeMessage;
  69. }
  70. internal set {
  71. welcomeMessage = value;
  72. }
  73. }
  74. public string ExitMessage {
  75. get {
  76. return exitMessage;
  77. }
  78. internal set {
  79. exitMessage = value;
  80. }
  81. }
  82. public FtpStatusCode StatusCode {
  83. get {
  84. return statusCode;
  85. }
  86. internal set {
  87. statusCode = value;
  88. }
  89. }
  90. public string StatusDescription {
  91. get {
  92. return statusDescription;
  93. }
  94. internal set {
  95. statusDescription = value;
  96. }
  97. }
  98. public override void Close ()
  99. {
  100. if (disposed)
  101. return;
  102. disposed = true;
  103. stream.Close ();
  104. stream = null;
  105. }
  106. public override Stream GetResponseStream ()
  107. {
  108. if (method != WebRequestMethods.Ftp.DownloadFile &&
  109. method != WebRequestMethods.Ftp.ListDirectory)
  110. CheckDisposed ();
  111. return stream;
  112. }
  113. internal Stream Stream {
  114. set {
  115. stream = value;
  116. }
  117. }
  118. internal void UpdateStatus (FtpStatusCode code, string desc)
  119. {
  120. statusCode = code;
  121. statusDescription = desc;
  122. }
  123. ~FtpWebResponse ()
  124. {
  125. ((IDisposable) this).Dispose ();
  126. }
  127. void CheckDisposed ()
  128. {
  129. if (disposed)
  130. throw new ObjectDisposedException (GetType ().FullName);
  131. }
  132. }
  133. }
  134. #endif