Backported fixes from HEAD
[mono.git] / mcs / class / System / System.Net / FtpWebResponse.cs
1 //
2 // System.Net.FtpWebResponse.cs
3 //
4 // Authors:
5 //      Carlos Alberto Cortez (calberto.cortez@gmail.com)
6 //
7 // (c) Copyright 2006 Novell, Inc. (http://www.novell.com)
8 //
9
10 using System;
11 using System.IO;
12 using System.Runtime.Serialization;
13 using System.Net;
14
15 #if NET_2_0
16
17 namespace System.Net
18 {
19         public class FtpWebResponse : WebResponse
20         {
21                 Stream stream;
22                 Uri uri;
23                 FtpStatusCode statusCode;
24                 DateTime lastModified = DateTime.MinValue;
25                 string bannerMessage = String.Empty;
26                 string welcomeMessage = String.Empty;
27                 string exitMessage = String.Empty;
28                 string statusDescription;
29                 string method;
30                 //bool keepAlive;
31                 bool disposed;
32                 internal long contentLength = -1;
33                 
34                 internal FtpWebResponse (Uri uri, string method, bool keepAlive)
35                 {
36                         this.uri = uri;
37                         this.method = method;
38                         //this.keepAlive = keepAlive;
39                 }
40
41                 internal FtpWebResponse (Uri uri, string method, FtpStatusCode statusCode, string statusDescription) {
42                         this.uri = uri;
43                         this.method = method;
44                         this.statusCode = statusCode;
45                         this.statusDescription = statusDescription;
46                 }
47
48                 internal FtpWebResponse (Uri uri, string method, FtpStatus status) :
49                         this (uri, method, status.StatusCode, status.StatusDescription)
50                 {
51                 }
52                 
53                 public override long ContentLength {
54                         get {
55                                 return contentLength;
56                         }
57                 }
58
59                 public override WebHeaderCollection Headers {
60                         get {
61                                 return new WebHeaderCollection ();
62                         }
63                 }
64
65                 public override Uri ResponseUri {
66                         get {
67                                 return uri;
68                         }
69                 }
70
71                 public DateTime LastModified {
72                         get {
73                                 return lastModified;
74                         }
75                         internal set {
76                                 lastModified = value;
77                         }
78                 }
79
80                 public string BannerMessage {
81                         get {
82                                 return bannerMessage;
83                         }
84                         internal set {
85                                 bannerMessage = value;
86                         }
87                 }
88                 
89                 public string WelcomeMessage {
90                         get {
91                                 return welcomeMessage;
92                         }
93                         internal set {
94                                 welcomeMessage = value;
95                         }
96                 }
97
98                 public string ExitMessage {
99                         get {
100                                 return exitMessage;
101                         }
102                         internal set {
103                                 exitMessage = value;
104                         }
105                 }
106
107                 public FtpStatusCode StatusCode {
108                         get {
109                                 return statusCode;
110                         }
111                         private set {
112                                 statusCode = value;
113                         }
114                 }
115
116                 public string StatusDescription {
117                         get {
118                                 return statusDescription;
119                         }
120                         private set {
121                                 statusDescription = value;
122                         }
123                 }
124                 
125                 public override void Close ()
126                 {
127                         if (disposed)
128                                 return;
129                         
130                         disposed = true;
131                         if (stream != null)
132                                 stream.Close ();
133                         stream = null;
134                 }
135
136                 public override Stream GetResponseStream ()
137                 {
138                         if (stream == null) {
139                                 throw new InvalidOperationException ();
140                         }
141                         
142                         if (method != WebRequestMethods.Ftp.DownloadFile &&
143                                         method != WebRequestMethods.Ftp.ListDirectory)
144                                 CheckDisposed ();
145                         
146                         return stream;
147                 }
148
149                 internal Stream Stream {
150                         set {
151                                 stream = value;
152                         }
153
154                         get { return stream; }
155                 }
156
157                 internal void UpdateStatus (FtpStatus status) {
158                         statusCode = status.StatusCode;
159                         statusDescription = status.StatusDescription;
160                 }
161
162                 void CheckDisposed ()
163                 {
164                         if (disposed)
165                                 throw new ObjectDisposedException (GetType ().FullName);
166                 }
167
168                 internal bool IsFinal () {
169                         return ((int) statusCode >= 200);
170                 }
171         }
172 }
173
174 #endif
175