Dll information:
Assembly/File Version: 1.0.0.132
Product Version 5.0.6.0
Issue:
When attempting to execute the following code the WinSCP.exe shows the UI and generates the following C# project (Exception: "Timeout waiting for WinSCP to respond."). The ExecutablePath is pointing to the WinSCP.exe which came with the .dll that Martin posted. The code below is based on the code sample posted here (https://winscp.net/eng/docs/library#csharp)?
Also, it still generates a bug if setting the session.ExeExecutablePath and not the session.ExecutablePath. The ExeExecutablePath does not seem to mentioned in the document here (https://winscp.net/eng/docs/library_session).
Thank you for the effort to develop this and I'll assist however I can.
All the best.
public bool SetFileViaSFTP(string fullFileName, string hostName, string remotePath, string userName, string password, string sshHostKey)
{
try
{
// Setup session options
SessionOptions sessionOptions = new SessionOptions();
sessionOptions.Protocol = Protocol.Sftp;
sessionOptions.HostName = hostName;
sessionOptions.UserName = userName;
sessionOptions.Password = password;
sessionOptions.SshHostKey = sshHostKey;
using (Session session = new Session())
{
// Connect
session.ExecutablePath = WebConfigurationManager.AppSettings["WinSCPExePath"] + "WinSCP.exe";
// session.ExeExecutablePath = WebConfigurationManager.AppSettings["WinSCPExePath"] + "WinSCP.exe";
session.Open(sessionOptions);
// Upload files
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Automatic;
TransferOperationResult transferResult;
transferResult = session.PutFiles(fullFileName, remotePath, false, transferOptions);
// Throw on any error
transferResult.Check();
// Print results
foreach (TransferEventArgs transfer in transferResult.Transfers)
{
Console.WriteLine("Upload of {0} succeeded", transfer.FileName);
}
}
Console.WriteLine("Success");
return true;
}
catch (Exception e)
{
Console.WriteLine("Failure: {0}", e);
return false;
}
}