Article ID: 812409 - Last Review: August 28, 2007 - Revision: 2.7 How To Write Pluggable Protocol to Support FTP in Managed Classes by Using Visual C# .NET For a Microsoft Visual Basic .NET version of this
article, see
812404
(http://support.microsoft.com/kb/812404/EN-US/
)
. On This PageSUMMARYThis step-by-step article describes how to write
pluggable protocol by using classes from the System.Net namespace. Microsoft .NET Framework provides a layered, extensible, and managed implementation of Internet services that can be integrated quickly and easily into your applications. The internet application that uses the request-response model can request data from the Internet in a protocol-agnostic manner. The .NET Framework uses specific classes to provide the three pieces of information that are required to access Internet resources through a request-response model: the URI class, the WebResponse class, and the WebRequest class. This article details how to use System.Net to write a pluggable protocol to support FTP in managed classes. Pluggable protocols can communicate in both synchronous and asynchronous modes. However, this article discusses only synchronous FTP communication. Asynchronous FTP is out of the scope of this article. The following file is available for download from the Microsoft Download Center: Collapse this image ![]() For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base: 119591
(http://support.microsoft.com/kb/119591/
)
How to Obtain Microsoft Support Files from Online Services
Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help to prevent any unauthorized changes to the file.
Note This sample will not work with CERN proxies. For additional information about CERN proxies, click the following article number 166961 to view the article 166961 in the Microsoft Knowledge Base: 166961
(http://support.microsoft.com/kb/166961/
)
How To FTP with CERN-Based Proxy
Using WinInet API
Create the FtpWebResponse and FtpWebRequest ClassesThe WebRequest and WebResponse classes are the basis of pluggable protocols. The descendant classes of WebRequest are registered with the WebRequest class to manage the details of making the actual connections to Internet resources.In the earlier example of FtpClient, the FtpWebResponse class inherits from the WebResponse class. You have to override ContentType and GetResponseStream methods. The ContentType property provides special information that the client requires to identify the type of content that is delivered by the server. The GetResponseStream method returns a data stream from the internet resource. In the earlier example, the FtpStream class is used to handle the data stream that is delivered to the server together with the request. The following sample code describes how this is done: The following example demonstrates the methods that are implemented or overridden in FtpWebRequest class. For more information and implementation, visit the Download Center for the FtpClient.exe file that is mentioned earlier in this article. Create FtpClientThe FtpClient application accesses the information from the Internet using a request-response model. You can retrieve protocol-specific information by using the WebRequest and WebResponse classes. To retrieve protocol-specific information, register the descendants of WebRequest by using the WebRequest.RegisterPrefix static method. The IWebRequestCreate interface defines the method that WebRequest descendants will use to register with the WebRequest.Create method.The following sample code demonstrates how to use IWebRequestCreate: The GetResponse method returns a WebResponse instance. The WebResponse provides access to the data that is returned by the server in the form of a stream returned by the GetResponseStream method. This stream can be used and modified in an application. You can derive a class from the stream class and override the method, based on application requirements. For more information, visit the Download Center for the FtpClient.exe file that is mentioned earlier in this article. Steps to Run the FtpClient Executable
REFERENCESFor more information, see the Microsoft .NET
Framework SDK documentation or visit the following MSDN Web site: Programming Pluggable
Protocols http://msdn.microsoft.com/en-us/library/1f6c88af(vs.71).aspx (http://msdn.microsoft.com/en-us/library/1f6c88af(vs.71).aspx) | Article Translations
|

Back to the top
