Using the Rexec class

Top  Previous  Next

The Rexec class allows you to connect to a remote host and execute a command. To use Rexec, you must pass in a username and password valid for the desired hostname.

 

Note

 

Using the Rexec class differs from using the Rsh class in that the Rexec class performs a full login while the Rsh class is strictly based on a Remote Host authentication configuration.

 

 

Example

This example demonstrates executing a directory listing command on a remote host using the Rexec class.

 

[C#]

using Jscape.Telnet;

 

namespace RexecTest {

 

       class RexecExample {

 

               [STAThread]

               static void Main(string[] args) {

 

                       // Instantiate Rexec

                       Rexec rexec = new Rexec();

 

                       // connect to Remote Host and execute directory listing command

                       byte[] response = rexec.Execute("remotehost.com", "username", "password", "ls -al");

 

                       // Get Remote Host response

                       string data = rexec.Encoding.GetString(response);

                       Console.WriteLine(data);

                       Console.WriteLine("Done.");

               }

       }

}

 

 

[Visual Basic]

Imports Jscape.Telnet

 

Module Module1

 

   Sub Main()

       ' Instantiate Rexec

       Dim myRexec As Rexec = New Rexec("remotehost.com", "username", "password", "ls -al")

 

       ' connect to Remote Host and execute directory listing command

       Dim response As Byte() = myRexec.Execute()

 

       ' Get Remote Host response

       Dim data As String = myRexec.Encoding.GetString(response)

       Console.WriteLine(data)

       Console.WriteLine("Done.")

 

   End Sub

 

End Module

 

 

See also

 

Remote Host authentication