本文整理汇总了C#中SshClient.RunCommand方法的典型用法代码示例。如果您正苦于以下问题:C# SshClient.RunCommand方法的具体用法?C# SshClient.RunCommand怎么用?C# SshClient.RunCommand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SshClient
的用法示例。
在下文中一共展示了SshClient.RunCommand方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RebootButton_Click
protected void RebootButton_Click(object sender, EventArgs e)
{
try
{
using (var client = new SshClient("ra-jetson.duckdns.org", "ubuntu", "savingL1v3s"))
{
client.Connect();
client.RunCommand("sudo /home/ubuntu/Desktop/bandhan/SQL-Scripts/./RightAlertRemoteRebootIssued-SQL"); // SSH Command Here
client.RunCommand("sudo reboot"); // SSH Command Here
client.Disconnect();
}
}
catch (Exception ex)
{
Response.Redirect("Down.html");
}
}
示例2: CleanCurrentFolder
public void CleanCurrentFolder()
{
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
{
client.Connect();
client.RunCommand("rm -rf *");
client.Disconnect();
}
}
示例3: Test_Run_SingleCommand
public void Test_Run_SingleCommand()
{
var host = Resources.HOST;
var username = Resources.USERNAME;
var password = Resources.PASSWORD;
using (var client = new SshClient(host, username, password))
{
#region Example SshCommand RunCommand Result
client.Connect();
var testValue = Guid.NewGuid().ToString();
var command = client.RunCommand(string.Format("echo {0}", testValue));
var result = command.Result;
result = result.Substring(0, result.Length - 1); // Remove \n character returned by command
client.Disconnect();
#endregion
Assert.IsTrue(result.Equals(testValue));
}
}
示例4: RemoveAllFiles
private static void RemoveAllFiles()
{
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
{
client.Connect();
client.RunCommand("rm -rf *");
client.Disconnect();
}
}
示例5: Test_Execute_Command_ExitStatus
public void Test_Execute_Command_ExitStatus()
{
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
{
client.Connect();
var cmd = client.RunCommand("exit 128");
Assert.IsTrue(cmd.ExitStatus == 128);
client.Disconnect();
}
}
示例6: Test_Execute_Command_ExitStatus
public void Test_Execute_Command_ExitStatus()
{
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
{
#region Example SshCommand RunCommand ExitStatus
client.Connect();
var cmd = client.RunCommand("exit 128");
Console.WriteLine(cmd.ExitStatus);
client.Disconnect();
#endregion
Assert.IsTrue(cmd.ExitStatus == 128);
}
}
示例7: Test_Ssh_Connect_Via_HttpProxy
public void Test_Ssh_Connect_Via_HttpProxy()
{
var connInfo = new PasswordConnectionInfo(Resources.HOST, Resources.USERNAME, Resources.PASSWORD, ProxyTypes.Http, Resources.PROXY_HOST, int.Parse(Resources.PROXY_PORT));
using (var client = new SshClient(connInfo))
{
client.Connect();
var ret = client.RunCommand("ls -la");
client.Disconnect();
}
}
示例8: RunCommandTest
public void RunCommandTest()
{
ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value
SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value
string commandText = string.Empty; // TODO: Initialize to an appropriate value
SshCommand expected = null; // TODO: Initialize to an appropriate value
SshCommand actual;
actual = target.RunCommand(commandText);
Assert.AreEqual(expected, actual);
Assert.Inconclusive("Verify the correctness of this test method.");
}
示例9: OnInit
protected override void OnInit()
{
base.OnInit();
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
{
client.Connect();
client.RunCommand("rm -rf *");
client.Disconnect();
}
}
示例10: RunCommand_CommandText_NeverConnected
public void RunCommand_CommandText_NeverConnected()
{
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password"))
{
try
{
client.RunCommand("ls");
Assert.Fail();
}
catch (SshConnectionException ex)
{
Assert.IsNull(ex.InnerException);
Assert.AreEqual("Client not connected.", ex.Message);
}
}
}