Our previous version application uses exact same version of Renci.SshNet.dll (2016.0.0.0). We haven't changed it since the beginning of the time. At the same time the code that is responsible to connect to the remote source (using Renci.SshNet.SftpClient for connection) and from the remote source folder to get the list of available files and to download them to local destination folder is the same as well, no changes. However, the old version of our application can connect to the same source and download the files, but the new version (with the same code and 3rd party dll reference) fails to download and throws the "Unexpectedly reached end of file exception" when calling the DownloadFile method of the SftpClient instance. Any idea what could have been changed?
IEnumerable<SftpFile> filesToTransfer = this.client.ListDirectory(remoteSourceFolder);
foreach (SftpFile file in filesToTransfer)
{
using (FileStream fs = File.Create(Path.Combine(destinationFolder, file.Name)))
{
this.client.DownloadFile(file.FullName, fs); // throws exception here
fs.Close();
}
}
In my case it turned out that there was a transitive reference to another version of Renci.SshNet.dll (2020.2.0) through the nuget package. I downgraded to my earlier version of 2016.0.0 and it worked well. So if you run into it just make sure the correct version of dll is used for you.