EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Question about SophisticatedSSHClient demo:

Posted: 05/02/2012 11:46:23
by Darrell Reinke (Standard support level)
Joined: 05/02/2012
Posts: 2

Question about SophisticatedSSHClient demo:

I am trying to get the SSH Send functionality working within your demo. I am able to successfully connect to the SSH site, however, SSHTunnelConnection is never instantiated, so when when I press the "Send" button on the demo form, nothing happens. Is there something special I need to get the send function working in the demo.

    Private Sub cmdConnect_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdConnect.Click
        If Not boolConnected Then
            SSHTunnelConnection = Nothing
            SSHClient.Versions = 0
            If chkSSH1.Checked Then
               SSHClient.Versions = SSHClient.Versions Or CShort(SBSSHCommon.Unit.sbSSH1)
            End If
            If chkSSH2.Checked Then
               SSHClient.Versions = SSHClient.Versions Or CShort(SBSSHCommon.Unit.sbSSH2)
            End If
            SSHClient.UserName = txtUserName.Text
            SSHClient.Password = txtPassword.Text
            Dim key As New TElSSHKey
            Dim privateKeyAdded As Boolean = False
            If txtPrivateKey.TextLength > 0 Then
                    Dim pwd As String
                    pwd = ""
                    If PromptForm.Prompt("Enter password for private key:", False, pwd) Then
                        Dim err As Integer
                        err = key.LoadPrivateKey(txtPrivateKey.Text, pwd)
                        If err = 0 Then
                            SSHClient.AuthenticationTypes = SSHClient.AuthenticationTypes Or SBSSHConstants.Unit.SSH_AUTH_TYPE_PUBLICKEY
                            privateKeyAdded = True
                            Log("Private key file could not be loaded due to error " + err.ToString)
                        End If
                    End If
            End If

            If Not privateKeyAdded Then
               SSHClient.AuthenticationTypes = SSHClient.AuthenticationTypes And Not SBSSHConstants.Unit.SSH_AUTH_TYPE_PUBLICKEY
            End If
            Dim hostadd As IPAddress = Dns.Resolve(txtHost.Text).AddressList(0)
            Dim epHost As New IPEndPoint(hostadd, Convert.ToInt32(txtPort.Text, 10))
            ClientSocket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
            ClientSocket.BeginConnect(epHost, New AsyncCallback(AddressOf clientSocket_OnOpenConnection), Nothing)

            cmdConnect.Text = "Disconnect"
         Catch ex As Exception
         End Try
        End If

    End Sub

When I click the send button, the following event is triggered, however, SSHTunnelConnection is still set to "Nothing" so the code doesn't fire. How do you initiate the SSHTunnelConnection? Am I missing something in your Demo App?

    Private Sub cmdSend_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdSend.Click
         If Not (SSHTunnelConnection Is Nothing) Then
            'Dim s As String = txtSend.Text + vbCr + vbTab
            'Dim buf As Byte() = Encoding.ASCII.GetBytes(s)
         End If
      Catch ex As Exception
      End Try
    End Sub

The connection to the SSH site is working. Please advise.
Posted: 05/02/2012 12:26:32
by Ken Ivanov (Team)

Thank you for contacting us.

1) Do you perform your experiments with out-of-the-box sample?
2) Have you got any connection errors reported in the application log (at the bottom of the sample's main window)? If there are no errors reported in the log, what other messages are there?
Posted: 05/02/2012 12:40:24
by Darrell Reinke (Standard support level)
Joined: 05/02/2012
Posts: 2

Yes. I am using your out-of-the-box example and there are no errors in the application log. As I described above. I receive a successfull connection, but just can't send a file once the connection has been given.

Here is the text I recieve upon successful connection
Client socket connected
Server key received (DSA). Fingerprint is 19:5d:21:90:08:94:0d:fc:b8:72:2e:50:e1:6e:4a:4d
Authentication succeeded
Connection started
Server: 0.0
Version: SSHv2
PublicKey algorithm: 0
Kex algorithm: 2
Block algorithm: 5
Compression algorithm: 0
MAC algorithm: 2

Once I enter a file path and click the send button, the following method is envoked and SSHTunnelConnection is set to "Nothing" so the SSHTunnelConnection.SendData(buf) won't run.

I have changed nothing in your sample code. Just wondering what populates the SSHTunnelConnection object?

Private Sub cmdSend_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdSend.Click
2.      Try
3.         If Not (SSHTunnelConnection Is Nothing) Then
4.            Dim s As String = txtSend.Text + vbCr + vbTab
5.            Dim buf As Byte() = Encoding.ASCII.GetBytes(s)
6.            SSHTunnelConnection.SendData(buf)
7.            'txtSend.Clear()
8.         End If
9.      Catch ex As Exception
10.         ShowErrorMessage(ex)
11.      End Try
12.    End Sub
Posted: 05/02/2012 13:10:08
by Ken Ivanov (Team)

This means that the shell tunnel is not opened for some reason. The SSHTunnelConnection object is passed to sshTunnel.OnOpen event when the shell channel is up and running. It seems that this event is not fired in your case, even though lower-level "transport" SSH connection is apparently established correctly.

A fairly common reason for such kind of problems is that terminal support is turned off on the server. Please try to set SSHTunnel.RequestTerminal to False and check if it changes anything.



Topic viewed 795 times

Number of guests: 1, registered members: 0, in total hidden: 0


Back to top

As of July 15, 2016 EldoS business operates as a division of /n software, inc. For more information, please read the announcement.

Got it!