This project is read-only.

Downloaded file is locked?

Jul 21, 2012 at 12:54 AM

Hi there

I'm using SFTP to download a file to a windows machine. After a successful download, when I go to open the file, I get a "permissions denied, the file is in use elsewhere". I assume this means my code and/or Recni.SFtp hasn't closed the file or something? Here's the code I'm using


            using (var client = new SftpClient(IPAddress, _SSHUserName, new PrivateKeyFile(File.OpenRead(_SSHLocalPrivateKeyFilepath)))) {
                Stream stream = File.OpenWrite(localFilepath);
                client.DownloadFile(remoteFilepath, stream);

Any ideas why the downloaded file is marked "in use" would be a great help. THanks!

PS. The software is working really well for me so far. Thanks!


Jul 21, 2012 at 1:04 AM

Jeeze, I just realized the simple answer: I need to close the stream afterward! Duh!