WebRequest using SSL
- by pm_2
I have the following code to retrieve a file using FTP (which works fine).
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(svrPath);
request.KeepAlive = true;
request.UsePassive = true;
request.UseBinary = true;
request.Method = WebRequestMethods.Ftp.DownloadFile;
request.Credentials = new NetworkCredential(uname, passw);
using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
using (Stream responseStream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(responseStream))
using (StreamWriter destination = new StreamWriter(destinationFile))
{
destination.Write(reader.ReadToEnd());
destination.Flush();
}
However, when I try to do this using SSL, I am unable to access the file, as follows:
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(svrPath);
request.KeepAlive = true;
request.UsePassive = true;
request.UseBinary = true;
// The following line causes the download to fail
request.EnableSsl = true;
request.Method = WebRequestMethods.Ftp.DownloadFile;
request.Credentials = new NetworkCredential(uname, passw);
using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
using (Stream responseStream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(responseStream))
using (StreamWriter destination = new StreamWriter(destinationFile))
{
destination.Write(reader.ReadToEnd());
destination.Flush();
}
Can anyone tell me why the latter would not work?