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