Results 1 to 2 of 2

Thread: SSH view command output in real time

  1. #1
    Nucleus is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 4.0
    Join Date
    May 2005
    Posts
    30
    Reputation
    146

    SSH view command output in real time

    Hi,
    I am trying to create an application that runs bash scripts on a remote Linux computer. The scripts already exist on the Linux computer, I just want to run them using this application. I'm using SSH NET by Renci to establish the SSH connection.

    The scripts are expected to provide full output of what's happening, and they do, but only after the whole script is finished, which could take up to 30 seconds. After the script is finished I get a full output of what happened when the script was running.

    I would like to see the output of the script while its running. Not after its finished.
    How can I do that?

    Code:
    Public Class SSH
        Dim connInfo As New Renci.SshNet.PasswordConnectionInfo("host", "port", "user", "pass")
        Dim cmd As Renci.SshNet.SshCommand
        Protected Sub btn1_Click(sender As Object, e As EventArgs) Handles btn1.Click
            Dim sshClient As New Renci.SshNet.SshClient(connInfo)
            Using sshClient
                sshClient.Connect()
                cmd = sshClient.RunCommand("/home/user/script1")
                rtbresult.Text = cmd.Result
                sshClient.Disconnect()
            End Using
        End Sub
        Protected Sub btn2_Click(sender As Object, e As EventArgs) Handles btn2.Click
            Dim sshClient As New Renci.SshNet.SshClient(connInfo)
            Using sshClient
                sshClient.Connect()
                cmd = sshClient.RunCommand("/home/user/script2")
                rtbresult.Text = cmd.Result
                sshClient.Disconnect()
            End Using
        End Sub
    End Class

  2. #2
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.5
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    15,080
    Reputation
    2802
    I've not used it, but seems possible due to this thread: wpf - SSH.NET real-time command output monitoring - Stack Overflow
    You would probably use CreateCommand, BeginExecute and StreamReader.ReadLine loop.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •