Browse DevX
Sign up for e-mail newsletters from DevX


Touring Whidbey's Base Class Library Enhancements : Page 6

The core API set underpinning managed application development in .NET—the Base Class Libraries (BCL)—have received several notable additions in the Whidbey release. Find out performance-based improvements, class-oriented feature additions, and the introduction of previously missing functionality through entirely new classes.

Managed Support for FTP
Support for issuing numerous types of network requests was provided by version 1.0 of the .NET Framework and the Base Class Libraries. A somewhat obviously missing feature from this network support involved the complete lack of a direct managed class for issuing FTP requests. This oversight is fixed in the Whidbey BCL. The FtpWebRequest class represents a basic FTP interface for issuing requests. The existing WebClient class now also supports the FTP protocol.

Use the Create method of the WebRequest class to obtain an instance of FtpWebRequest. A valid user name and password are required and should be wrapped in a NetworkCredentials class and assigned to the Credentials property of the FtpWebRequest instance. The specific FTP command to issue is controlled by setting the Methods property to one of the values of the FtpMethods structure as follows:

  • AppendFile
  • DeleteFile
  • DownloadFile
  • GetFileSize
  • ListDirectory
  • UploadFile
The return value of an FTP request should be obtained by calling the GetResponseStream method to obtain an instance of the FtpWebResponse class, as shown below:
   Const file As String = "ftp://.../Demofile.txt"
   Dim ftpReq As FtpWebRequest = _ 
   ftpReq.Method = FtpMethods.DownloadFile
   ftpReq.Credentials = New NetworkCredential( _   
      "anonymous", "demopwd")
   Dim ftpResp As FtpWebResponse 
   ftpResp = ftpReq.GetResponse
   Dim ftpRespStream As Stream
   Dim reader As StreamReader
   ftpRespStream = ftpResp.GetResponseStream
   reader = New IO.StreamReader(ftpRespStream, _
The simplest approach to downloading files from an FTP server is provided by the new file transfer protocol supported by the WebClient class. Use the DownloadFile method to issue an FTP request for a file and save it immediately to a file on the local file system, as shown below:
   Dim client As New WebClient
   Dim reader As StreamReader
   client.Credentials = New NetworkCredential( _
      "anonymous", "demopwd")
   client.DownloadFile(TargetFile, "C:\Demofile.txt")
If the destination for a file to be downloaded from an FTP server is not the local file system but the current process, use the DownloadData method of WebClient to retrieve file contents directly, as shown below:
   Const target As String = "ftp://.../Demofile.txt"
   Dim client As New WebClient
   Dim reader As StreamReader
   'This example assumes anonymous logon.
   client.Credentials = New NetworkCredential( _ 
      "anonymous", "demopwd")
   Dim destFile As String 
   destFile =  Encoding.UTF8.GetString( _
The Base Class Libraries provide the basic foundation for just about every task an application needs to perform. The process of creating a standardized set of consistent application programming interfaces includes the inevitable burden of keeping up with the expectations of the developer community. The task undertaken by the Framework team at Microsoft to craft a collection of APIs that could simultaneously serve as the foundation for a whole new generation of applications, provide a bridge between the Framework and its predecessor (COM), and unite and satisfy the demands of hard core developers from the Visual Basic, C++, and third-party language camps is substantial. The only task that could conceivably be more difficult might be to improve substantially on this set of Base Class Libraries.

Although I can only cover a fraction of the changes appearing in the Whidbey BCL here, the changes I did cover should show that significant additions and enhancements to the Base Class Libraries are forthcoming. You can assume that many things will change as the Framework team moves forward into the Beta stages. New features will surface, additional enhancements will be fleshed out and completed, and odds are, maybe even a feature or two will be cut back or removed.

If you step back for a second and look at the enhancements already showing up in the alpha build of Whidbey, you should feel very confident. Given this first look at Whidbey, the future of .NET and the future of application development as a whole seems very strong.

Michael Lane Thomas , also known as the .NET Cowboy for his sometimes untamed, Wild West-style passion for .NET, has been a fixture in the development community for many years. A speaker at professional, academic, and Microsoft-internal technical conferences, Michael has been a primary contributor to 26 books, including a multi-year stint as .NET Series Editor for Wiley's/Hungry Minds, going back to the beta days of .NET. Michael has spent time as industry analyst, commentator, and co-host of a weekly radio talk show. As an exam-junkie, Michael is currently the eighth most certified MCP in the world, passing a total of 62 exams to date. Michael is currently a Developer Evangelist for Microsoft and greatly enjoys exploring the alpha bits for Whidbey as a Microsoft VS .NET Insider and his role of daddy to his one-year-old son Noah, also known as "Mr. Pinchy Cheeks." You can reach him here.
Thanks for your registration, follow us on our social networks to keep up-to-date