My First .Net 2.0 Gripe: System.Net.Webclient


You’re cobbling together a little utility that does file uploads in your shiny new VS2005…

And you want to upload a file to a server using HTTP, HTTPS or FTP…

And you find the System.Net.Webclient class, and think “Wow! That looks perfect!”

And you find it does everything you need it to do in about four lines of code…

And you find your FTP server doesn’t like passive FTP (500 Unrecognized Command PASV)…

And you find that while the FtpWebRequest class has a UsePassive property that can be set to False…

And you find that the System.Net.Webclient doesn’t expose that property, so anytime you encounter an Active only FTP server, you’re toast…

And while re-implementing all the FTP stuff already in Webclient with System.Net.FtpWebRequest/FtpWebResponse, you wonder why they couldn’t have just exposed that one little property.

4 thoughts on “My First .Net 2.0 Gripe: System.Net.Webclient

  1. Could a have a complete example of this:
    “and it looks like you might be able to inherit from WebClient and override the protected GetWebRequest() method”

  2. I have found it , and now does work! OK.
    I don’t have to rewrite it.

    Imports System.Net

    Friend Class MyWebClient
    Inherits WebClient

    Protected Overloads Overrides Function GetWebRequest(ByVal address As Uri) As WebRequest
    Dim req As FtpWebRequest = CType(MyBase.GetWebRequest(address), FtpWebRequest)
    req.UsePassive = False
    Return req
    End Function
    End Class

Comments are closed.