Network error: Software caused connection abort
I am trying send files from one machine to other through SFTP, but always getting error through the code, while I am sending the file from WinSCP GUI then it always successfully sent. Only issue through the .NET code. Below is the code I have done.
var sessionOptions = new SessionOptions(); sessionOptions.Protocol = Protocol.Sftp; sessionOptions.HostName = pHostName; sessionOptions.UserName = pUserName; sessionOptions.Password = pPassword; sessionOptions.PortNumber = pPortNumber; sessionOptions.Timeout = TimeSpan.FromSeconds(600); sessionOptions.SshHostKeyFingerprint = pHostKey; using (var session = new Session()) { // Connect try { session.DisableVersionCheck = true; } catch (Exception ex) { } finally { GC.Collect(); } session.DebugLogLevel = 1; session.DebugLogPath = @"D:\winscp_log\debug\debug.log"; session.Open(sessionOptions); logwriter.WriteLine(DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + "****************WinSCP Session established"); var transferOptions = new TransferOptions(); transferOptions.TransferMode = TransferMode.Binary; transferOptions.OverwriteMode = OverwriteMode.Overwrite; TransferOperationResult transferResult; if (pCloudTransfer == true) { logwriter.WriteLine(DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + "****************Inside cloud transfer flag."); transferResult = session.PutFiles(pInputFolderName + @"\*.csv", "/" + pCUploadFolder + "/", true, transferOptions); } else { logwriter.WriteLine(DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + "****************Inside dubai server flag."); transferResult = session.PutFiles(pInputFolderName + @"\*.csv", "/" + pDUploadFolder + "/", true, transferOptions); } // Throw on any error transferResult.Check(); // Print results foreach (TransferEventArgs transfer in transferResult.Transfers) { Console.WriteLine(DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + "****************Upload of " + transfer.FileName + " succeeded"); logwriter.WriteLine(DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + "****************Upload of " + transfer.FileName + " succeeded"); } }