Cook Computing

The requested FTP command is not supported when using HTTP proxy

July 18, 2006 Written by Charles Cook

I was using the FtpUpload task from the MSBuild Community Tasks Project and after moving to a different machine started catching an InvalidOperationException with the message "The requested FTP command is not supported when using HTTP proxy". It turns out that only the RETR, LIST, and NLST methods are supported by System.Net. FtpWebRequest when a HTTP proxy is configured and it doesn't matter that you are not setting a proxy in your code: if a HTTP proxy (not FTP proxy) is configured in the system proxy settings (i.e. what you see in your Internet Explorer properties), then you will get this error when trying to upload to the FTP server.

The workaround is use IE to change the system settings to switch off the use of the HTTP proxy. However if you have access to the affected code the solution is to set the Proxy property of the request to null, for example:


WebRequest request = WebRequest.Create("ftp://myserver/foo");
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential("user", "pwd");
request.Proxy = null;
Stream requestStream = request.GetRequestStream();
// ...