SSH - ctrl + d with ssh.net

71 views Asked by At

I would like to send a SSH command via C# SSH.NET to a device. I am unfortunately trapped in a window where I can only get out with CTRL + D.

What is the best way to do this?

My code:

        private async Task VPNgwSSHsender(string dialognetzFWip, string dialognetzClientip, string ipkt1, string ipkt2, string ipkt3, string ipkt4, string ipAdF, string fwB, string fwPW, string kdNr, string spdnsHB, string spdnsPW, string öfIPArvato, string GWIPdS, string WANIP, string IntIP, string PSK, string lgID, string konIP, string dialognetz, string fwlizenz)
        {
            try
            {
                await Task.Run(async () =>
                {
                    // Verbindung zu SSH1 herstellen
                    using (var ssh1 = new SshClient(ipAdF, fwB, fwPW))
                    {
                        ssh1.Connect();

                        string logFilePath = Path.Combine(Path.GetTempPath(), "TIaaS-VPN-GW.log");
                        using (StreamWriter sw = File.AppendText(logFilePath))
                        {
                            string[] commands = new string[]
                            {
                            "system register",
                            fwlizenz,
                            "\x04",
                            };

                            var sshStream = ssh1.CreateShellStream("xterm", 80, 24, 800, 600, 1024);
                            foreach (var command in commands)
                            {
                                sw.WriteLine(command);
                                sshStream.WriteLine(command);
                                sshStream.Flush();

                                if (command == fwlizenz)
                                {
                                    Thread.Sleep(2000);
                                }
                            }
                        }

                        ssh1.Disconnect();
                    }

Thanks! Steffen

"\x04", or ((char)4).ToString(), or "exit", unfortunately does not work

0

There are 0 answers