WebRequest using SSL
        Posted  
        
            by pm_2
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by pm_2
        
        
        
        Published on 2010-06-15T08:08:11Z
        Indexed on 
            2010/06/15
            8:12 UTC
        
        
        Read the original article
        Hit count: 382
        
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?
© Stack Overflow or respective owner