Error: "Failed to open local file", upon downloading file

Jun 3, 2013 at 6:58 AM
Hi,

I've created a basic SFTP client. I am successful in listing the directories and was also able to upload files to server. But, I am receiving the error "Failed to open local file", when I try to download file.

Below is the code that I used :
using (var sftp = new SftpClient(textBox1.Text, textBox2.Text, textBox3.Text))
 {
         folderBrowserDialog1.ShowDialog();
         string localFileName = folderBrowserDialog1.SelectedPath;
         sftp.Connect();
         string remoteFileName = sftp.WorkingDirectory + "\\" + "Demo.pptx";
         using (var file = File.Exists(localFileName + "\\" + "SampleFile.pptx") == false ? System.IO.File.OpenWrite(localFileName + "\\" + "SampleFile.pptx") : System.IO.File.Create(localFileName + "\\" + "SampleFile.pptx"))
         {
                 sftp.DownloadFile(remoteFileName, file);
         }
}
sftp.Disconnect();
Am I missing anything?