Login  
Search All Forums
Dart Home | PowerTCP SFTP & SSH for .NET | Custom Development Reply | PowerTCP SFTP & SSH for .NET Topics | Forums   
AuthorForum: PowerTCP SFTP & SSH for .NET
Topic: How to eliminate terminal control characters from incoming stream?
raymegal

From: USA
Posts: 20
Member Since: 09/18/14
posted March 2, 2018 10:27 PM

Starting a session and then capturing the data coming back I get stuff like this:



  Directory: C:\                               


Mode        LastWriteTime     Length Name             
----        -------------     ------ ----             
d-----    7/13/2009  5:20 PM        PerfLogs           
d-r---    2/28/2018  3:01 PM        Program Files         
d-r---    10/14/2017  2:11 PM        Program Files (x86)      

I'm guessing these are terminal control characters (https://stackoverflow.com/questions/20319505/interpreting-ssh-output)

I using the default StartSession(), which should be starting a "dumb" terminal.

Is there a way to have the session eliminate the terminal control characters?
raymegal

From: USA
Posts: 20
Member Since: 09/18/14
posted March 2, 2018 10:51 PM

If there isn't I resorted to trying this suggestion: https://superuser.com/questions/380772/removing-ansi-color-codes-from-text-stream

Which resulted in this bit of code:

      var data = Regex.Replace(e.Data.ToString(), @"\x1b\[[0-9;]*[a-zA-Z]", "");
      Log.Info(data);

It works but seems clunky (AKA hack).
Nick B (Admin)

From: Utica, NY USA
Posts: 619
Member Since: 05/25/10

Extra Support Options
Custom Application Development

posted March 5, 2018 5:27 PM

Hello,

The default StartSession overload does create a "dumb" terminal (specifying "dumb" as the terminaltype), so either the server is incorrectly including VT control characters, doesn't correctly handle the "dumb" terminal type generally, or the application/command you're executing on the server is designed to include them regardless of the terminal type. Resolutions like the one you've specified are one way to deal with them.

Our PowerTCP Emulation for .NET parses and renders VT52/VT100/VT220/VT320 control characters:
http://www.dart.com/emulation-net-vt-telnet-api.aspx
And supports screen-scraping, so you'd be able to approximate the intended display of the server's response when screen-scraping (assuming you are using a text log or console for output as it appears per your other forum post. Note that PowerTCP Emulation for .NET's VT control when used as a visual control, displays the response as intended (double-sized characters, etc), but these cannot be fully correctly handled by text or a console output (we approximate the best possible output when screen-scraping such characters)).

We include a SSH and VT sample, so you'd be able to easily test this out first/before purchase, if desired.
raymegal

From: USA
Posts: 20
Member Since: 09/18/14
posted March 5, 2018 5:44 PM

We're talking to an OpenSSH server running on a Windows 2008 R2 box in this instance. I haven't dug into the OpenSSH code but it looks like it doesn't honor the "dumb" terminal specification.

We are automating a session so the VT emulation is overkill for us. All we need to do is prompt/reply stuff and log the interaction. The control characters clutter the log so I will continue to ditch them unless you want to share another way to deal with them without emulation.
Reply | PowerTCP SFTP & SSH for .NET Topics | Forums   
This site is powered by PowerTCP WebServer Tool PowerTCP WebServer for ActiveX