Post a reply

Before posting, please read how to report bug or request support effectively.

Bug reports without an attached log file are usually useless.

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

NoBullMan

connect timeout using WinSCPNet in web application

I am working on a web application where one function is to connect to a remote Linux server using SFTP, download some log files, parse and display the results. I am using WinSCP to achieve this.

I got this working and tested it running from VS in my local dev box (Windows 10). I published it to a test server running Windows 2012 R2 and it fails to connect. It throws:
Timeout waiting for WinSCP to respond - WinSCP has not responded in time. There was no output. Response log file C:\Windows\TEMP\wscp3BFC.0292A297.tmp was not created.

I searched and it seems in IIS, impersonation had to be off and I had it on; that change did not fix the issue either although WinSCP support page lists it as a fix.

When I remote to test server, open IIS, select the application and run it from there it works fine; so I know there are no issues with user ID, password, port or host key fingerprint. I spent the whole day and am at at wit's end. Some ideas is most welcome.

This is the code I am using:
public SFTP(string sHost, int iPort, string sUserID, string sPassword, string SshHostKeyFingerprint, string ExePath)
{
    SFTP_Host = sHost;
    SFTP_Port = iPort;
    SFTP_UserID = sUserID;
    SFTP_Password = sPassword;
    SFTP_SshHostKeyFingerprint = SshHostKeyFingerprint;
    ExePath = ExePath;
}
 
public void ConnectSFTP()
{
    // Set up session options
    SessionOptions sessionOptions = new SessionOptions
    {
        Protocol = Protocol.Sftp,
        HostName = SFTP_Host,
        PortNumber = SFTP_Port,
        UserName = SFTP_UserID,
        Password = SFTP_Password,
        SshHostKeyFingerprint = SFTP_SshHostKeyFingerprint
    };
    sessionOptions.AddRawSettings("Cipher", "aes,chacha20,3des,WARN,des,blowfish,arcfour");
    SFTP_Session = new Session();
    SFTP_Session.ExecutablePath = ExePath;
    //SFTP_Session.XmlLogPath = "Z:\\Data\\WinSCP.xml";
    //SFTP_Session.SessionLogPath = @"Z:\Data\WinSCP.log";
 
    // Connect
    try
    {
        SFTP_Session.Open(sessionOptions);
        TraceLog.appendTransactionLog("Connected to " + SFTP_Host + ":" + SFTP_Port);
    }
    catch (Exception ex)
    {
        TraceLog.appendTransactionLog("Failed to connect to " + SFTP_Host + ":" + SFTP_Port + Environment.NewLine + "Error: " + ex.Message);
    }
    finally
    {
        if (SFTP_Session != null)
        {
            SFTP_Session.Dispose();
        }
    }
}


It is called like this:
SFTP client = new SFTP(sftpHost, iSftpPort, sftpUserID, sftpPassword, sshHostKeyFingerprint, ExePath);
client.DownloadFiles();
 
public string DownloadFiles()
{
    ConnectSFTP();    // FAILS HERE ...
 
    try
    {
        using (SFTP_Session)
        {
            SFTP_Session.QueryReceived += (sender, e) =>
            {
            e.Continue();
            }
        };
        ....
    }
    catch (Exception e)
    {
        ...
    }
    finally
    {
        if (SFTP_Session != null)
        {
            SFTP_Session.Dispose();
        }
    }
}

I see in my log file (not WinSCP since it can connect):
2021-07-02 08:24:56:169|Failed to connect to 1.2.3.4:22 (ssh-ed25519-hK8U-......)
Error: Timeout waiting for WinSCP to respond - WinSCP has not responded in time. There was no output. Response log file C:\Windows\TEMP\wscp3BFC.0292A297.tmp was not created. This could indicate lack of write permissions to the log folder or problems starting WinSCP itself.
WinSCP version is 5.17.10.0.