Problem: I created a SQL Server CLR stored procedure today from a C# utility dll to upload files to an FTP server. When I tried to execute the CLR stored procedure, I got the following error.
[code="html"]
Msg 6522, Level 16, State 1, Procedure usp_FtpUploadFile, Line 0
A .NET Framework error occurred during execution of user-defined routine or aggregate "usp_mct_FtpUploadFile":
System.InvalidOperationException: The requested FTP command is not supported when using HTTP proxy.
System.InvalidOperationException:
at System.Net.FtpWebRequest.GetHttpWebRequest()
at System.Net.FtpWebRequest.GetRequestStream()
at mycodetrip.com.Utils.FtpUtils.UploadFile(SqlString ftpServerAndFolder, SqlString uploadFileName, SqlString ftpUser, SqlString ftpPassword, SqlString localSourceFileFolder)
.
[/code]
What was surprising was that my NUnit test in C# that called my utility method “UploadFile” worked fine. However, when I created a SQL Server CLR stored procedure from the same utility method’s assembly and tried to run in from within SQL Server I got this error.
Solution: After a bit of investigation, I found that the error was happening because the method call from SQL Server was attempting to use the HttpProxy on the Server machine. If the proxy is not set to null explicitly in your code, then you will get this error.
So to fix it, set the Proxy of the request object to null as follows (see line # 3) .
C# Version
[code="csharp"]
FtpWebRequest request =
(FtpWebRequest)WebRequest.Create((string)ftpServerAndFolder + "/" + (string)uploadFileName);
// set proxy to null to avoid the System.InvalidOperationException: The requested FTP command is not supported when using HTTP proxy.
request.Proxy = null;
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential((string)ftpUser, (string)ftpPassword);
[/code]
VB.Net Version
[code="vb"]
FtpWebRequest request =
CType(WebRequest.Create(CType(ftpServerAndFolder + "/" + CType(uploadFileName, string, String))), FtpWebRequest)
' set proxy to null to avoid the System.InvalidOperationException: The requested FTP command is not supported when using HTTP proxy.
request.Proxy = Nothing
request.Method = WebRequestMethods.Ftp.UploadFile
request.Credentials = New NetworkCredential(CType(ftpUser, CType(ftpPassword, string, String)))
[/code]







1530
I dont find above solution valueable because i still found some error again and again.
1558
Worked great for me. I simulated the problem by starting up a local proxy using Fiddler and got the above error from my ftp function. The addition of request.proxy = nothing solved the issue and files can now publish through the proxy… awesome. Thanks!
1562
Solved my problem beautifully. Thank You! Thank You!
1563
Thanks, you saved the day!