Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / Net / System / Net / FtpWebResponse.cs / 1 / FtpWebResponse.cs
// ------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// -----------------------------------------------------------------------------
//
namespace System.Net {
using System.Collections;
using System.IO;
using System.Net.Sockets;
using System.Threading;
using System.Security.Cryptography.X509Certificates ;
using System.Security.Permissions;
///
/// The FtpWebResponse class contains the result of the FTP request
/// interface.
///
public class FtpWebResponse : WebResponse, IDisposable {
internal Stream m_ResponseStream;
private long m_ContentLength;
private Uri m_ResponseUri;
private FtpStatusCode m_StatusCode;
private string m_StatusLine;
private WebHeaderCollection m_FtpRequestHeaders;
private HttpWebResponse m_HttpWebResponse;
private DateTime m_LastModified;
private string m_BannerMessage;
private string m_WelcomeMessage;
private string m_ExitMessage;
internal FtpWebResponse(Stream responseStream, long contentLength, Uri responseUri, FtpStatusCode statusCode, string statusLine, DateTime lastModified, string bannerMessage, string welcomeMessage, string exitMessage) {
GlobalLog.Print("FtpWebResponse#" + ValidationHelper.HashString(this) + "::.ctor(" + contentLength.ToString() + ","+ statusLine+ ")");
m_ResponseStream = responseStream;
if (responseStream == null && contentLength < 0) {
contentLength = 0;
}
m_ContentLength = contentLength;
m_ResponseUri = responseUri;
m_StatusCode = statusCode;
m_StatusLine = statusLine;
m_LastModified = lastModified;
m_BannerMessage = bannerMessage;
m_WelcomeMessage = welcomeMessage;
m_ExitMessage = exitMessage;
}
internal FtpWebResponse(HttpWebResponse httpWebResponse) {
m_HttpWebResponse = httpWebResponse;
InternalSetFromCache = m_HttpWebResponse.IsFromCache;
InternalSetIsCacheFresh = m_HttpWebResponse.IsCacheFresh;
}
internal void UpdateStatus(FtpStatusCode statusCode, string statusLine, string exitMessage) {
m_StatusCode = statusCode;
m_StatusLine = statusLine;
m_ExitMessage = exitMessage;
}
///
/// Returns a data stream for FTP
///
public override Stream GetResponseStream()
{
Stream responseStream = null;
if (HttpProxyMode) {
responseStream = m_HttpWebResponse.GetResponseStream();
}
else if (m_ResponseStream != null) {
responseStream = m_ResponseStream;
}
else {
responseStream = m_ResponseStream = new EmptyStream();
}
return responseStream;
}
//
internal class EmptyStream: MemoryStream
{
internal EmptyStream():base(new byte[0], false)
{
}
}
//
// Only used when combining cached and live responses
//
internal void SetResponseStream(Stream stream)
{
if (stream == null || stream == Stream.Null || stream is EmptyStream)
return;
m_ResponseStream = stream;
}
///
/// Closes the underlying FTP response stream, but does not close control connection
///
public override void Close() {
if(Logging.On)Logging.Enter(Logging.Web, this, "Close", "");
if (HttpProxyMode) {
m_HttpWebResponse.Close();
} else {
Stream stream = m_ResponseStream;
if (stream != null) {
stream.Close();
}
}
if(Logging.On)Logging.Exit(Logging.Web, this, "Close", "");
}
///
/// Queries the length of the response
///
public override long ContentLength {
get {
if (HttpProxyMode) {
return m_HttpWebResponse.ContentLength;
}
return m_ContentLength;
}
}
internal void SetContentLength(long value)
{
if (HttpProxyMode)
return; //m_HttpWebResponse.ContentLength = value;
m_ContentLength = value;
}
///
///
/// A collection of headers, currently nothing is return except an empty collection
///
///
public override WebHeaderCollection Headers {
get {
if (HttpProxyMode) {
return m_HttpWebResponse.Headers;
}
if (m_FtpRequestHeaders == null) {
lock(this) {
if (m_FtpRequestHeaders == null) {
m_FtpRequestHeaders = new WebHeaderCollection(WebHeaderCollectionType.FtpWebResponse);
}
}
}
return m_FtpRequestHeaders;
}
}
///
/// Shows the final Uri that the FTP request ended up on
///
public override Uri ResponseUri {
get {
if (HttpProxyMode) {
return m_HttpWebResponse.ResponseUri;
}
return m_ResponseUri;
}
}
///
/// Last status code retrived
///
public FtpStatusCode StatusCode {
get {
if (HttpProxyMode) {
return ((FtpStatusCode) ((int) m_HttpWebResponse.StatusCode));
}
return m_StatusCode;
}
}
///
/// Last status line retrived
///
public string StatusDescription {
get {
if (HttpProxyMode) {
return m_HttpWebResponse.StatusDescription;
}
return m_StatusLine;
}
}
///
/// Returns last modified date time for given file (null if not relavant/avail)
///
public DateTime LastModified {
get {
if (HttpProxyMode) {
return m_HttpWebResponse.LastModified;
}
return m_LastModified;
}
}
///
/// Returns the server message sent before user credentials are sent
///
public string BannerMessage {
get {
return m_BannerMessage;
}
}
///
/// Returns the server message sent after user credentials are sent
///
public string WelcomeMessage {
get {
return m_WelcomeMessage;
}
}
///
/// Returns the exit sent message on shutdown
///
public string ExitMessage {
get {
return m_ExitMessage;
}
}
///
/// True if request is just wrapping HttpWebRequest
///
private bool HttpProxyMode {
get {
return (m_HttpWebResponse != null);
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// ------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// -----------------------------------------------------------------------------
//
namespace System.Net {
using System.Collections;
using System.IO;
using System.Net.Sockets;
using System.Threading;
using System.Security.Cryptography.X509Certificates ;
using System.Security.Permissions;
///
/// The FtpWebResponse class contains the result of the FTP request
/// interface.
///
public class FtpWebResponse : WebResponse, IDisposable {
internal Stream m_ResponseStream;
private long m_ContentLength;
private Uri m_ResponseUri;
private FtpStatusCode m_StatusCode;
private string m_StatusLine;
private WebHeaderCollection m_FtpRequestHeaders;
private HttpWebResponse m_HttpWebResponse;
private DateTime m_LastModified;
private string m_BannerMessage;
private string m_WelcomeMessage;
private string m_ExitMessage;
internal FtpWebResponse(Stream responseStream, long contentLength, Uri responseUri, FtpStatusCode statusCode, string statusLine, DateTime lastModified, string bannerMessage, string welcomeMessage, string exitMessage) {
GlobalLog.Print("FtpWebResponse#" + ValidationHelper.HashString(this) + "::.ctor(" + contentLength.ToString() + ","+ statusLine+ ")");
m_ResponseStream = responseStream;
if (responseStream == null && contentLength < 0) {
contentLength = 0;
}
m_ContentLength = contentLength;
m_ResponseUri = responseUri;
m_StatusCode = statusCode;
m_StatusLine = statusLine;
m_LastModified = lastModified;
m_BannerMessage = bannerMessage;
m_WelcomeMessage = welcomeMessage;
m_ExitMessage = exitMessage;
}
internal FtpWebResponse(HttpWebResponse httpWebResponse) {
m_HttpWebResponse = httpWebResponse;
InternalSetFromCache = m_HttpWebResponse.IsFromCache;
InternalSetIsCacheFresh = m_HttpWebResponse.IsCacheFresh;
}
internal void UpdateStatus(FtpStatusCode statusCode, string statusLine, string exitMessage) {
m_StatusCode = statusCode;
m_StatusLine = statusLine;
m_ExitMessage = exitMessage;
}
///
/// Returns a data stream for FTP
///
public override Stream GetResponseStream()
{
Stream responseStream = null;
if (HttpProxyMode) {
responseStream = m_HttpWebResponse.GetResponseStream();
}
else if (m_ResponseStream != null) {
responseStream = m_ResponseStream;
}
else {
responseStream = m_ResponseStream = new EmptyStream();
}
return responseStream;
}
//
internal class EmptyStream: MemoryStream
{
internal EmptyStream():base(new byte[0], false)
{
}
}
//
// Only used when combining cached and live responses
//
internal void SetResponseStream(Stream stream)
{
if (stream == null || stream == Stream.Null || stream is EmptyStream)
return;
m_ResponseStream = stream;
}
///
/// Closes the underlying FTP response stream, but does not close control connection
///
public override void Close() {
if(Logging.On)Logging.Enter(Logging.Web, this, "Close", "");
if (HttpProxyMode) {
m_HttpWebResponse.Close();
} else {
Stream stream = m_ResponseStream;
if (stream != null) {
stream.Close();
}
}
if(Logging.On)Logging.Exit(Logging.Web, this, "Close", "");
}
///
/// Queries the length of the response
///
public override long ContentLength {
get {
if (HttpProxyMode) {
return m_HttpWebResponse.ContentLength;
}
return m_ContentLength;
}
}
internal void SetContentLength(long value)
{
if (HttpProxyMode)
return; //m_HttpWebResponse.ContentLength = value;
m_ContentLength = value;
}
///
///
/// A collection of headers, currently nothing is return except an empty collection
///
///
public override WebHeaderCollection Headers {
get {
if (HttpProxyMode) {
return m_HttpWebResponse.Headers;
}
if (m_FtpRequestHeaders == null) {
lock(this) {
if (m_FtpRequestHeaders == null) {
m_FtpRequestHeaders = new WebHeaderCollection(WebHeaderCollectionType.FtpWebResponse);
}
}
}
return m_FtpRequestHeaders;
}
}
///
/// Shows the final Uri that the FTP request ended up on
///
public override Uri ResponseUri {
get {
if (HttpProxyMode) {
return m_HttpWebResponse.ResponseUri;
}
return m_ResponseUri;
}
}
///
/// Last status code retrived
///
public FtpStatusCode StatusCode {
get {
if (HttpProxyMode) {
return ((FtpStatusCode) ((int) m_HttpWebResponse.StatusCode));
}
return m_StatusCode;
}
}
///
/// Last status line retrived
///
public string StatusDescription {
get {
if (HttpProxyMode) {
return m_HttpWebResponse.StatusDescription;
}
return m_StatusLine;
}
}
///
/// Returns last modified date time for given file (null if not relavant/avail)
///
public DateTime LastModified {
get {
if (HttpProxyMode) {
return m_HttpWebResponse.LastModified;
}
return m_LastModified;
}
}
///
/// Returns the server message sent before user credentials are sent
///
public string BannerMessage {
get {
return m_BannerMessage;
}
}
///
/// Returns the server message sent after user credentials are sent
///
public string WelcomeMessage {
get {
return m_WelcomeMessage;
}
}
///
/// Returns the exit sent message on shutdown
///
public string ExitMessage {
get {
return m_ExitMessage;
}
}
///
/// True if request is just wrapping HttpWebRequest
///
private bool HttpProxyMode {
get {
return (m_HttpWebResponse != null);
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ErrorActivity.cs
- SQLInt64Storage.cs
- ComponentResourceKey.cs
- ConfigPathUtility.cs
- ConfigUtil.cs
- XpsDocumentEvent.cs
- ImmutableAssemblyCacheEntry.cs
- TimeSpanStorage.cs
- SymbolUsageManager.cs
- Window.cs
- LinqDataView.cs
- StickyNoteAnnotations.cs
- XamlRtfConverter.cs
- TimelineClockCollection.cs
- CaseInsensitiveOrdinalStringComparer.cs
- XmlSchemaAttributeGroup.cs
- Color.cs
- Rotation3DAnimationBase.cs
- PlaceHolder.cs
- StateValidator.cs
- DependencyObjectPropertyDescriptor.cs
- MetadataArtifactLoaderResource.cs
- DeleteBookmarkScope.cs
- DataGridItemAttachedStorage.cs
- IdnElement.cs
- SQLStringStorage.cs
- ConnectionInterfaceCollection.cs
- RenderContext.cs
- ContainerParaClient.cs
- XMLSyntaxException.cs
- PointF.cs
- ConstraintManager.cs
- CodePageUtils.cs
- ObjectHelper.cs
- MenuItemStyle.cs
- ComboBox.cs
- EarlyBoundInfo.cs
- UrlMappingsModule.cs
- SkewTransform.cs
- DataServiceQueryException.cs
- TransactionFilter.cs
- CanonicalFormWriter.cs
- RenderDataDrawingContext.cs
- WindowsNonControl.cs
- CompiledQuery.cs
- SimpleTableProvider.cs
- GridLength.cs
- DataServiceEntityAttribute.cs
- AvTraceFormat.cs
- JsonObjectDataContract.cs
- DataGridViewColumnStateChangedEventArgs.cs
- HttpModulesSection.cs
- DateTimeFormat.cs
- HiddenField.cs
- OdbcConnection.cs
- CustomAttribute.cs
- TemplateContent.cs
- ServiceDescriptionImporter.cs
- ConfigurationProperty.cs
- Int32AnimationBase.cs
- MultiBinding.cs
- UrlMappingsSection.cs
- TrackingStringDictionary.cs
- ObjectDataSourceFilteringEventArgs.cs
- EntityTypeEmitter.cs
- BoolExpr.cs
- CompositionAdorner.cs
- ArraySegment.cs
- Vector3DValueSerializer.cs
- ExpressionHelper.cs
- DateTimeOffsetConverter.cs
- RequestCacheManager.cs
- DetailsViewPageEventArgs.cs
- DnsPermission.cs
- SiteMapNode.cs
- BindingNavigator.cs
- ApplicationManager.cs
- Repeater.cs
- XamlSerializer.cs
- CodeTypeDeclarationCollection.cs
- DefinitionUpdate.cs
- TextBoxView.cs
- FactoryId.cs
- WebServiceEnumData.cs
- HttpApplicationStateWrapper.cs
- IconEditor.cs
- SmiEventStream.cs
- IdentityValidationException.cs
- WorkflowMarkupSerializerMapping.cs
- HttpAsyncResult.cs
- WindowsGraphicsCacheManager.cs
- TreeNodeCollection.cs
- NaturalLanguageHyphenator.cs
- InfoCardSchemas.cs
- XsltArgumentList.cs
- TextEditorSpelling.cs
- HtmlInputCheckBox.cs
- SqlCacheDependency.cs
- PixelFormat.cs
- StorageSetMapping.cs