FtpWebResponse.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. using System.Net;
  13. #if NET_2_0
  14. namespace System.Net
  15. {
  16. public class FtpWebResponse : WebResponse
  17. {
  18. Stream stream;
  19. Uri uri;
  20. FtpStatusCode statusCode;
  21. DateTime lastModified = DateTime.MinValue;
  22. string bannerMessage = String.Empty;
  23. string welcomeMessage = String.Empty;
  24. string exitMessage = String.Empty;
  25. string statusDescription;
  26. string method;
  27. //bool keepAlive;
  28. bool disposed;
  29. internal long contentLength = -1;
  30. internal FtpWebResponse (Uri uri, string method, bool keepAlive)
  31. {
  32. this.uri = uri;
  33. this.method = method;
  34. //this.keepAlive = keepAlive;
  35. }
  36. internal FtpWebResponse (Uri uri, string method, FtpStatusCode statusCode, string statusDescription) {
  37. this.uri = uri;
  38. this.method = method;
  39. this.statusCode = statusCode;
  40. this.statusDescription = statusDescription;
  41. }
  42. internal FtpWebResponse (Uri uri, string method, FtpStatus status) :
  43. this (uri, method, status.StatusCode, status.StatusDescription)
  44. {
  45. }
  46. public override long ContentLength {
  47. get {
  48. return contentLength;
  49. }
  50. }
  51. public override WebHeaderCollection Headers {
  52. get {
  53. return new WebHeaderCollection ();
  54. }
  55. }
  56. public override Uri ResponseUri {
  57. get {
  58. return uri;
  59. }
  60. }
  61. public DateTime LastModified {
  62. get {
  63. return lastModified;
  64. }
  65. internal set {
  66. lastModified = value;
  67. }
  68. }
  69. public string BannerMessage {
  70. get {
  71. return bannerMessage;
  72. }
  73. internal set {
  74. bannerMessage = value;
  75. }
  76. }
  77. public string WelcomeMessage {
  78. get {
  79. return welcomeMessage;
  80. }
  81. internal set {
  82. welcomeMessage = value;
  83. }
  84. }
  85. public string ExitMessage {
  86. get {
  87. return exitMessage;
  88. }
  89. internal set {
  90. exitMessage = value;
  91. }
  92. }
  93. public FtpStatusCode StatusCode {
  94. get {
  95. return statusCode;
  96. }
  97. private set {
  98. statusCode = value;
  99. }
  100. }
  101. public string StatusDescription {
  102. get {
  103. return statusDescription;
  104. }
  105. private set {
  106. statusDescription = value;
  107. }
  108. }
  109. public override void Close ()
  110. {
  111. if (disposed)
  112. return;
  113. disposed = true;
  114. if (stream != null)
  115. stream.Close ();
  116. stream = null;
  117. }
  118. public override Stream GetResponseStream ()
  119. {
  120. if (stream == null)
  121. return Stream.Null; // After a STOR we get this
  122. if (method != WebRequestMethods.Ftp.DownloadFile &&
  123. method != WebRequestMethods.Ftp.ListDirectory)
  124. CheckDisposed ();
  125. return stream;
  126. }
  127. internal Stream Stream {
  128. set {
  129. stream = value;
  130. }
  131. get { return stream; }
  132. }
  133. internal void UpdateStatus (FtpStatus status) {
  134. statusCode = status.StatusCode;
  135. statusDescription = status.StatusDescription;
  136. }
  137. void CheckDisposed ()
  138. {
  139. if (disposed)
  140. throw new ObjectDisposedException (GetType ().FullName);
  141. }
  142. internal bool IsFinal () {
  143. return ((int) statusCode >= 200);
  144. }
  145. }
  146. }
  147. #endif