We have a .NET console application that is using WinSCP version 5.9.3 to SFTP files. We have this code in various .NET EXEs that we have scheduled to run every 30 minutes to transfer different files. During a single day, we may have 30 jobs run to transfer up to 60 files in total. Normally, the jobs don't have any issues and the files are transferred successfully. However, every so often, 1 or 2 of these jobs fail for the "Timeout waiting for WinSCP to respond" message. Sometimes, 3 or 4 of the jobs fail in a given day or it could run fine for an an entire week. Any suggestions on how to resolve these timeout errors?
The .Net code is listed below. IT basically reads some settings from a configuration file and then does the WinSCP logic to put the file on the SFTP.
[code]string HostName = ConfigObject.GetValueForSectionKey(sectionGroup + "/" + sectionName, "HostName");
int PortNumber = Int32.Parse(ConfigObject.GetValueForSectionKey(sectionGroup + "/" + sectionName, "PortNumber"));
string UserName = ConfigObject.GetValueForSectionKey(sectionGroup + "/" + sectionName, "UserName");
string Password = ConfigObject.GetValueForSectionKey(sectionGroup + "/" + sectionName, "Password");
string sshHostKeyFingerprint = ConfigObject.GetValueForSectionKey(sectionGroup + "/" + sectionName, "SshHostKeyFingerprint");
string HostPath = ConfigObject.GetValueForSectionKey(sectionGroup + "/" + sectionName, "HostPath");
string sftp_TransferMode = ConfigObject.GetValueForSectionKey(sectionGroup + "/" + sectionName, "SFTP_TransferMode");
SessionOptions SFTP_SessionOptions = new SessionOptions();
SFTP_SessionOptions = SetupSFTP_SessionOptions(HostName, PortNumber, UserName, Password, sshHostKeyFingerprint);
using (Session session = new Session())
{
//Connect
session.SessionLogPath = WinSCPSessionLogPath + Path.GetFileNameWithoutExtension(WinSCPSessionLogFileName) + "_" + DateTime.Now.ToString("yyyyMMdd_hhmmss") + Path.GetExtension(WinSCPSessionLogFileName);
session.DisableVersionCheck = true;
session.Open(SFTP_SessionOptions);
TransferOptions transferOptions = new TransferOptions();
transferOptions.ResumeSupport.State = TransferResumeSupportState.Off;
switch (sftp_TransferMode)
{
case "Ascii":
transferOptions.TransferMode = TransferMode.Ascii;
break;
case "Automatic":
transferOptions.TransferMode = TransferMode.Automatic;
break;
case "Binary":
transferOptions.TransferMode = TransferMode.Binary;
break;
default:
transferOptions.TransferMode = TransferMode.Automatic;
break;
}
//Upload the file
session.PutFiles(fullfilename, HostPath, false, transferOptions).Check();
}[/code]
In case you need the config settings, I've listed them below:
[code]<!-- ************************************************************* -->
<!-- FTP Settings -->
<!-- ************************************************************* -->
<add key="HostName" value="ftp.xxxxxx.com"/>
<add key="PortNumber" value="22"/>
<add key="UserName" value="xxxxxxxx"/>
<add key="Password" value="xxxxxxxx"/>
<add key="SshHostKeyFingerprint" value="ssh-dss 1024 9c:70:28:cf:c6:dc:d1:cf:08:d2:be:42:80:18:ec:c7"/>
<add key="HostPath" value="/Triggered_Automations/PBS/01_ImGoing/Stage/"/>
<add key="SFTP_TransferMode" value="Binary"/>
<!-- ************************************************************* -->
<!-- WinSCP Settings -->
<!-- ************************************************************* -->
<add key="WinSCPSessionLogPath" value="\\MyServer\Apps\EM_ET\WinSCP_Logs\"/>
<add key="WinSCPSessionLogFileName" value="winscp_session.log"/>
<add key="UseDefault_WinSCPServerResponseTimeout" value="false"/>
<add key="WinSCPServerResponseTimeout" value="300"/>[/code]
I've attached the Session Log file as well. Please let me know if you need any additional information and I appreciate any help.