Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

.net ssh, wait command execute

private void button1_Click(object sender, EventArgs e)
{
    new Task(() => RunCommand()).Start();
}

private void RunCommand()
{
    var host = "hostname";
    var username = "username";
    var password = "password";

    using (var client = new SshClient(host, username, password))
    {
        client.Connect();
        // If the command2 depend on an environment modified by command1,
        // execute them like this.
        // If not, use separate CreateCommand calls.
        var cmd = client.CreateCommand("command1; command2");

        var result = cmd.BeginExecute();

        using (var reader =
                   new StreamReader(cmd.OutputStream, Encoding.UTF8, true, 1024, true))
        {
            while (!result.IsCompleted || !reader.EndOfStream)
            {
                string line = reader.ReadLine();
                if (line != null)
                {
                    textBox1.Invoke(
                        (MethodInvoker)(() =>
                            textBox1.AppendText(line + Environment.NewLine)));
                }
            }
        }

        cmd.EndExecute(result);
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: why process not found in c# 
Csharp :: C# create delegate type at runtime 
Csharp :: RemoveClaim 
Csharp :: ip validation .net core 
Csharp :: Runtime.getRuntime().addShutdownHook(printingHook); c# 
Csharp :: c# string to control name 
Csharp :: prometheus add prefix to metrics 
Csharp :: c# is not 
Csharp :: orderby make sunday last day c# 
Csharp :: ? in c# 
Csharp :: nunit return parameter 
Csharp :: multiple lines in string c# parameterized 
Csharp :: unity gamemanager instance not set to an instance of an object 
Csharp :: how to use external resource.resx file in c# 
Csharp :: ef null check 
Csharp :: getcomponent rigidbody2d 
Csharp :: rigidbody velocity 
Csharp :: bitwise and c# 
Csharp :: rate game in unity 
Csharp :: unity on key press 
Csharp :: c# is not marked as serializable 
Csharp :: .Net 6 Program.cs 
Csharp :: winforms open multiple forms show one icon in taskabr 
Csharp :: C# program to find the longest Palindrome in a string. 
Html :: link css to html 
Html :: accept only image input file 
Html :: twitter share link html 
Html :: html disable enter submit 
Html :: rails add favicon 
Html :: bootstrap 5 font weight 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =