コード例 #1
0
 public MacTelnet(SshShellStream shellStream, string mac, string identity)
 {
     _shellStream = shellStream;
     _mac         = mac;
     _identity    = identity;
     _login       = false;
 }
コード例 #2
0
ファイル: Shell.cs プロジェクト: simonfgit/AutoVLANrepo
        public void RunOnNeighbor2(string mac, string identity, string user, string pass, string cmd)
        {
            using (var client = new SshClient(_host, _user, _pass))
            {
                client.Connect();
                var shellStream = new SshShellStream(client.CreateShellStream("xterm", 80, 600, 0, 0, 32 * 1024), debug: true);
                var macTelnet   = new MacTelnet(shellStream, mac, identity);

                if (!macTelnet.Login(user, pass))
                {
                    throw new Exception("Can't login");
                }

                var          actions      = new List <SshShellAction>();
                const string startActions = "start_actions";
                const string endActions   = "end_actions";

                actions.Add(shellStream.NewAction(startActions, $"{cmd}; :put {endActions};"));
                actions.Add(shellStream.NewAction(endActions, "/quit"));

                var result = macTelnet.Run($":put {startActions};", actions);
                if (!result)
                {
                    throw new Exception("Can't run actions");
                }
                client.Disconnect();
            }
        }