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