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