Quantcast
Viewing all articles
Browse latest Browse all 1729

New Post: Command running problem

I want to use ssh library to connect to windows server and fire command on Power Shell. My code is as follows
    ConnectionInfo connectionInfo = new PasswordConnectionInfo("ip",port, "id", "password");
    using (Renci.SshNet.SshClient client = new Renci.SshNet.SshClient(connectionInfo))
    {           
            client.Connect();
            var output = new MemoryStream();
            var shell = client.CreateShell(Encoding.ASCII, "Get-Service | Out-String", output, output);

            shell.Start();

            byte[] tempBytes = new byte[output.Length];
            output.Read(tempBytes, 0, tempBytes.Length);

            System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
            string result = enc.GetString(tempBytes);

            lbl.Text = "Output: " + result;

            shell.Stop();
            output.Close();
            output.Flush();
            output.Dispose();
     }
It is neither generating any error nor it does display anything in output. Can anybody help me out please..

Viewing all articles
Browse latest Browse all 1729

Trending Articles