I am retrieving a file from our FTP server which is then put into memory and passed to the client via HTTPS. I have everything working flawlessly. However, if I turn on SSL, I get the following error:
WebException: The remote server returned an error: (500) Syntax error,
command unrecognized.]
System.Net.FtpWebRequest.SyncRequestCallback(Object obj) +330
System.Net.FtpWebRequest.RequestCallback(Object obj) +23
System.Net.CommandStream.InvokeRequestCallback(Object obj) +17
System.Net.CommandStream.Abort(Exception e) +168
System.Net.FtpWebRequest.FinishRequestStage(RequestStage stage) +454
System.Net.FtpWebRequest.GetResponse() +1398
Here is my code:
FtpWebRequest ftp = (FtpWebRequest)WebRequest.Create(@"ftp://" + serverName + ":21/" + fileName);
ftp.Credentials = new NetworkCredential(userName, password);
ftp.UseBinary = true;
ftp.EnableSsl = true;
ftp.Method = WebRequestMethods.Ftp.DownloadFile;
FtpWebResponse response = null;
response = (FtpWebResponse)ftp.GetResponse();
If I set http://ftp.EnableSsl to false or just comment it out, it works fine. Any ideas as to what I am doing wrong. Keep in mind, I am on a Windows XP Professional box using the IIS built in FTP Server. I am debugging from IIS and I am running under https://localhost/projectNameHere/default.aspx.
If you trust the server, you can override Validation process to your need.
Your connection and data will still be secure. You should not use this code if you don’t trust the source, since the source can be impersonator.