Skip to content

SSH.NET" Version=2020.0.0 #767

Closed
Closed

Description

@alona0610

Hi
I have a problem with SSH.Net 2020.0.0 When trying to SFTP file to Linux Server.
I am using .Net Core 3.1 under IIS.

The error that I am getting randomly is that the server is timing out.
Renci.SshNet.Common.SshOperationTimeoutException: Connection failed to establish within 30000 milliseconds.

Below is my code.
var connectionInfo = new RenciSftp.ConnectionInfo(this.FileServerHost,
this.FileServerUsername,
new RenciSftp.PasswordAuthenticationMethod(this.FileServerUsername, this.FileServerPassword));

        using (var client = new RenciSftp.SftpClient(connectionInfo))
        {
            try
            {
                client.Connect();
                client.ChangeDirectory(remoteDir);
                client.BufferSize = 4 * 1024; // bypass Payload error large files
                using (var fileStream = fileStorage.GetFileStream(session))
                {
                    client.UploadFile(fileStream, serverFilename);
                }
            }

            catch (Renci.SshNet.Common.SshConnectionException ex)
            {
                this.AddUploadError("ERROR","SshConnectionException", hostName + ";  " +  IP, ex.ToString());
            }
            catch (System.Net.Sockets.SocketException ex)
            {
                this.AddUploadError("ERROR", "SocketException", hostName + "; " + IP, ex.ToString());
            }

            catch (Renci.SshNet.Common.SshAuthenticationException ex)
            {
                this.AddUploadError("ERROR","SshAuthenticationException", hostName + ";  " + IP, ex.ToString());
            }
            catch (Exception ex)
            {
                this.AddUploadError("ERROR","General Error", hostName + ";  " + IP, ex.ToString());
            }

            client.Disconnect();
            client.Dispose();

}

Activity

  1. alona0610 commented on Jan 27, 2021

    @alona0610
    Author

    Any info on that error?

  2. vvvarunv commented on Feb 25, 2021

    @vvvarunv

    With 2020.0.1 I am also seeing similar errors

    connection time(ms) : 30013, exception : Renci.SshNet.Common.SshOperationTimeoutException: Session operation has timed out

    I reverted to 2016.1.0 and things are fine now

    This is when trying to SSH into a Cisco router.

  3. vvvarunv commented on Feb 25, 2021

    @vvvarunv

    @drieseng : Any update on this?

  4. drieseng commented on Feb 27, 2021

    @drieseng
    Member

    Can any of you give me (private) access to a server/device that I can use to reproduce this issue?

  5. Sparin commented on Jun 24, 2021

    @Sparin

    Hi everyone!

    We (on my job) recently met this error on connecting to Cisco Catalyst 9300-48UN-A Switch (Cisco IOS XE 16.12.2s). In our case, we unexpectedly stuck at awaiting SSH_MSG_KEXINIT from the Cisco switch after a few successful connections. It's just awaiting 30 seconds for timeout and drop the connection then.

    During a sniffing session, we've concluded switch awaits SSH_MSG_KEXINIT from us for no reason. We tried to move sending SSH_MSG_KEXINIT from the KeyExchange.cs file/procedure just before the awaiting SSH_MSG_KEXINIT from the server at Session.cs. Looking to RFC 4253 Section 7 and source code of SSH.NET, I didn't find any reason to awaits SSH_MSG_KEXINIT from the server. So it looks like a race condition deadlock.

    Our step to reproduce a little bit the same

    1. Deploy any ASP.NET Core or .NET Core 3.1 server under IIS 10 deployment
    2. Invoke your SSH.NET code to Cisco at anyways for multiple times
    3. First attempts probably will be fine, but after some time you'll get a deadlock

    Our code snippet which we are testing

    public bool IsKeyValid(string userName, string privateKey)
    {
        using var privateKeyStream = new MemoryStream(Encoding.ASCII.GetBytes(privateKey));
        using var sshClient = new SshClient(_address, _port ?? 22, userName, new PrivateKeyFile(privateKeyStream));
        sshClient.Connect();
    
        return sshClient.IsConnected;
    }

    Can any of you give me (private) access to a server/device that I can use to reproduce this issue?

    @drieseng We don't have direct access to the switch and server with this problem, but maybe we can agree on a Zoom session with the owner. But probably they'll decline the request for NDA reasons

  6. WojciechNagorski commented on Dec 21, 2023

    @WojciechNagorski
    Collaborator

    It's done in #1274

  7. added this to the 2023.0.1 milestone on Dec 21, 2023
  8. WojciechNagorski commented on Dec 29, 2023

    @WojciechNagorski
    Collaborator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions