.NET intermittently getting "Timeout waiting for WinSCP to respond"
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.