Quantcast
Channel: sshnet Discussions Rss Feed
Viewing all articles
Browse latest Browse all 1729

New Post: StreamReader content and non printable characters

$
0
0
Hello Comminuty,

i have 2 questions.

1) I use SSH.NET for Shell connection to SSH hosts with
public class Connector
    {
        SshClient ssh;
        StreamReader read;
        StreamWriter write;
        ShellStream shell;
        Thread readerThread;

        public Connector(string ip, string user, string password)
        {
            Console.CancelKeyPress += Console_CancelKeyPress;
            ssh = new SshClient(ip, user, password);
            readerThread = new Thread(new ThreadStart(Reader));
            readerThread.Start();
            Connector2();
        }

        void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e)
        {
            write.Write('\x003');
        }
        public void Connector2()
        {
            ssh.Connect();
            shell = ssh.CreateShellStream("vt100", 80, 24, 800, 600, 1024);
            read = new StreamReader(shell);
            write = new StreamWriter(shell);
            Console.TreatControlCAsInput = true;
            do
            {
                write.Write(Console.ReadKey().KeyChar);
                write.Flush();

            } while (ssh.IsConnected);
        }

        private void Reader()
        {
            while (true)
            {                
                System.Threading.Thread.Sleep(10);
                if(!ssh.IsConnected) continue;
                if (read == null)
                    continue;
                string result = read.ReadToEnd();
                if (string.IsNullOrEmpty(result))
                    continue;
                Console.Write(result);
            }
        }
    }
But StreamReader not only returns console output, it also returns my input.
For example, i type "ping 8.8.8.8" and got "ppiinngg 88..88..88..88" in console window. It is not an functionality issue, its more optical issue.

2) Like point 1, its more optical issue. I have sometimes non printable characters form a MikroTik router, but never had non printable characters when using putty oder something else.
♥←[K    ←[m←[32msent=←[m5 ←[m←[32mreceived=←[m5 ←[m←[32mpacket-loss=←[m0% ←[m←[3
2mmin-rtt=←[m3ms ←[m←[32mavg-rtt=←[m3ms ←[m←[32mmax-rtt=←[m3ms
In putty it the same link is
    sent=5 received=5 packet-loss=0% min-rtt=2ms avg-rtt=2ms max-rtt=3ms
Any solutions for this?

Regards
Manuel

Viewing all articles
Browse latest Browse all 1729

Trending Articles