Creating a script |
A script is a set of tasks that are to be performed in sequence. An SshScript instance represents the script for one or more tasks to be executed on the SSH server. To create a script simply create a new SshScript instance passing a Ssh instance as its argument.
Example
[C#]
// create login credentials
SshParameters sshParams = new SshParameters(hostname,username,password);
// create new Ssh instance
Ssh ssh = new Ssh(sshParams);
// create new SshScript and associate with Ssh instance
SshScript script = new SshScript(ssh);
// create first task
SshTask task1 = new SshTask("$","ls -al","$");
// create second task
SshTask task2 = new SshTask("$","pwd","$");
// add tasks to script to be executed in order
script.AddTask(task1);
script.AddTask(task2);
// connect and execute tasks
ssh.Connect();
// wait until last task is complete
while(!task2.IsComplete) {
Thread.Sleep(100);
}
// print out results of task1
Console.WriteLine(task1.Response);
// print out results of task2
Console.WriteLine(task2.Response);
// disconnect
ssh.Disconnect();
[VB]
' create login credentials
Dim sshParams As SshParameters = New SshParameters(hostname, username, password)
' create new Ssh instance
Dim ssh As Ssh = New Ssh(sshParams)
' create new SshScript and associate with Ssh instance
Dim script As SshScript = New SshScript(ssh)
' create first task
Dim task1 As SshTask = New SshTask("$", "ls -al", "$")
' create second task
Dim task2 As SshTask = New SshTask("$", "pwd", "$")
' add tasks to script to be executed in order
script.AddTask(task1)
script.AddTask(task2)
' connect and execute tasks
ssh.Connect
' wait until last task is complete
While Not task2.IsComplete
Thread.Sleep(100)
End While
' print out results of task1
Console.WriteLine(task1.Response)
' print out results of task2
Console.WriteLine(task2.Response)
' disconnect
ssh.Disconnect