views:

208

answers:

2

I use FtpWebRequest to do some FTP stuff and I need to connect directly (no proxy). However WebRequest.DefaultWebProxy contains IE proxy settings (I reckon).

WebRequest request = WebRequest.Create("ftp://someftpserver/");
// request.Proxy is null here so setting it to null does not have any effect
WebResponse response = request.GetResponse();
// connects using WebRequest.DefaultWebProxy

My code is a piece in a huge application and I don't want to change WebRequest.DefaultWebProxy because it is global static property and it can have adverse impact on the other parts of the application.

Any idea how to do it?

+1  A: 

try setting the proxy to an empty WebProxy, ie:

request.Proxy = new WebProxy();

This should create an empty proxy.

Alastair Pitts
Yeah, that does the trick. Thanks
Elephantik
No probs, this one stumped me a little while ago.
Alastair Pitts
A: 

Actually setting it to null will be enough as well to disable auto proxy detection, you might save some cycles :)

request.Proxy = null;

http://msdn.microsoft.com/en-us/library/fze2ytx2.aspx

dr. evil
Actually, setting to null didn't help if I remember correctly (as said in the snippet comment). Disabling auto proxy detection would affect the rest of the application which I can't do either. Thanks anyway
Elephantik