Overview
This article will demonstrate how to use rsh in .NET using Telnet Factory for .NET.
Code Example
Download TelnetLicense.txt
| Download RSH.cs
| Download RSH_N.vb
1: using System;
2: using System.Collections.Generic;
3: using System.Text;
4: using Jscape.Telnet;
5: using Jscape.Telnet.Options;
6:
7: namespace RSH_NET
8: {
9: class RSH
10: {
11: static void Main(string[] args)
12: {
13: try
14: {
15: // Instantiate Rsh
16: Rsh rsh = new Rsh();
17: // copy license key here
18: rsh.LicenseKey = null;
19: // connect to Remote Host and execute directory listing command
20: byte[] response = rsh.Execute("remotehost.com", "username", "ls -al");
21: // Get Remote Host response
22: string data = rsh.Encoding.GetString(response);
23: Console.WriteLine(data);
24: Console.WriteLine("Done.");
25: }
26: catch (Exception e)
27: {
28: Console.WriteLine(e.Message);
29: }
30:
31: Console.WriteLine("Press any key to continue ... ");
32: Console.Read();
33: }
34: }
35: }
Lines 1-5 : Necessary import statements.
Line 16 : Initialize Rsh instance.
Line 20 : Read response from server.
Comments