string command = <your command>;
using (var ssh = new SshClient(connectionInfo))
{
ssh.Connect();
string reply = String.Empty;
try
{
using (var shellStream = ssh.CreateShellStream("dumb", 0, 0, 0, 0, BUFFERSIZE))
{
// Wait for promt for 10 seconds, if time expires, exception is thrown
reply = shellStream.Expect(new Regex(@":.*>"), new TimeSpan(0, 0, 10));
shellStream.WriteLine(command);
// Wait for Read for 10 seconds, if time expires, exception is thrown
string result = shellStream.ReadLine(new TimeSpan(0, 0, 10));
}
}
catch
{
// Do something
}
}
↧
New Post: Sample code for SSH shell
↧