System.InvalidOperationException: Element session@0 already read to the end
Hello,
I'm using WinSCP .NET assembly version 6.3.5.
We have a process to download the images from FTP server, it loops through files need to be downloaded, if the file does not exist on the server, it moves to next file. We noticed that when 10-12 files not found in sequence, WinSCP throwing exception with message (from SessionLog.txt) file "You are being kicked off the server. Goodbye ABC from IP Address.".
.NET exception it shows is "System.InvalidOperationException: Element session@0 already read to the end".
Here code snippet
Transfer.cs file:
DonwloadImages.cs
I'm using WinSCP .NET assembly version 6.3.5.
We have a process to download the images from FTP server, it loops through files need to be downloaded, if the file does not exist on the server, it moves to next file. We noticed that when 10-12 files not found in sequence, WinSCP throwing exception with message (from SessionLog.txt) file "You are being kicked off the server. Goodbye ABC from IP Address.".
.NET exception it shows is "System.InvalidOperationException: Element session@0 already read to the end".
Here code snippet
Transfer.cs file:
var sessionOptions = new SessionOptions { Protocol = p, PortNumber = port, FtpSecure = (FtpSecure)ftpMode, FtpMode = FtpMode.Passive, TimeoutInMilliseconds = Int32.MaxValue,//Insanely large number...because I need it HostName = server, UserName = userName, Password = password }; if (p != Protocol.Ftp) sessionOptions.SshHostKeyFingerprint = hostKey; _session = new Session(); _session.Open(sessionOptions);
using (var ftp = new Transfer(Protocol.Ftp)) { foreach (var fld in imageDirLst) { if (!ftp.DownloadFile(RootFolder + fld.FileFolder + "/", fld.Name, locDest, 0)) { log.Error("Failed to download file"); } } }