Merge pull request #205 from m3rlinez/master
[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                 FtpWebRequest request;
33                 internal long contentLength = -1;
34                 
35                 internal FtpWebResponse (FtpWebRequest request, Uri uri, string method, bool keepAlive)
36                 {
37                         this.request = request;
38                         this.uri = uri;
39                         this.method = method;
40                         //this.keepAlive = keepAlive;
41                 }
42
43                 internal FtpWebResponse (FtpWebRequest request, Uri uri, string method, FtpStatusCode statusCode, string statusDescription)
44                 {
45                         this.request = request;
46                         this.uri = uri;
47                         this.method = method;
48                         this.statusCode = statusCode;
49                         this.statusDescription = statusDescription;
50                 }
51
52                 internal FtpWebResponse (FtpWebRequest request, Uri uri, string method, FtpStatus status) :
53                         this (request, uri, method, status.StatusCode, status.StatusDescription)
54                 {
55                 }
56                 
57                 public override long ContentLength {
58                         get {
59                                 return contentLength;
60                         }
61                 }
62
63                 public override WebHeaderCollection Headers {
64                         get {
65                                 return new WebHeaderCollection ();
66                         }
67                 }
68
69                 public override Uri ResponseUri {
70                         get {
71                                 return uri;
72                         }
73                 }
74
75                 public DateTime LastModified {
76                         get {
77                                 return lastModified;
78                         }
79                         internal set {
80                                 lastModified = value;
81                         }
82                 }
83
84                 public string BannerMessage {
85                         get {
86                                 return bannerMessage;
87                         }
88                         internal set {
89                                 bannerMessage = value;
90                         }
91                 }
92                 
93                 public string WelcomeMessage {
94                         get {
95                                 return welcomeMessage;
96                         }
97                         internal set {
98                                 welcomeMessage = value;
99                         }
100                 }
101
102                 public string ExitMessage {
103                         get {
104                                 return exitMessage;
105                         }
106                         internal set {
107                                 exitMessage = value;
108                         }
109                 }
110
111                 public FtpStatusCode StatusCode {
112                         get {
113                                 return statusCode;
114                         }
115                         internal set {
116                                 statusCode = value;
117                         }
118                 }
119
120                 public string StatusDescription {
121                         get {
122                                 return statusDescription;
123                         }
124                         internal set {
125                                 statusDescription = value;
126                         }
127                 }
128                 
129                 public override void Close ()
130                 {
131                         if (disposed)
132                                 return;
133                         
134                         disposed = true;
135                         if (stream != null) {
136                                 stream.Close ();
137                                 if (stream == Stream.Null)
138                                         request.OperationCompleted ();
139                         }
140                         stream = null;
141                 }
142
143                 public override Stream GetResponseStream ()
144                 {
145                         if (stream == null)
146                                 return Stream.Null; // After a STOR we get this
147                         
148                         if (method != WebRequestMethods.Ftp.DownloadFile &&
149                                         method != WebRequestMethods.Ftp.ListDirectory)
150                                 CheckDisposed ();
151                         
152                         return stream;
153                 }
154
155                 internal Stream Stream {
156                         set {
157                                 stream = value;
158                         }
159
160                         get { return stream; }
161                 }
162
163                 internal void UpdateStatus (FtpStatus status) {
164                         statusCode = status.StatusCode;
165                         statusDescription = status.StatusDescription;
166                 }
167
168                 void CheckDisposed ()
169                 {
170                         if (disposed)
171                                 throw new ObjectDisposedException (GetType ().FullName);
172                 }
173
174                 internal bool IsFinal () {
175                         return ((int) statusCode >= 200);
176                 }
177         }
178 }
179
180 #endif
181