Sooo…
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.
I’m just having the same problem, and it looks like you might be able to inherit from WebClient and override the protected GetWebRequest() method to check whether the request is an FtpWebRequest and if so, clear UsePassive.
See the example here: http://msdn2.microsoft.com/en-us/library/system.net.webclient.getwebrequest.aspx
I reckon you have already figured that out, and that’s still more than four lines of code, but here you go anyhow.
Didn’t even occur to me! Thanks!
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”
regards,
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