Making telnet work in Windows shell

I’m writing a Windows application which needs Plink (Putty Link) for authorization to set up an interactive session with a Linux machine. The Plink command is working fine from the Windows command line and from a .BAT file, but not with Xojo shell.execute, which just times out. I have seen this post: so I think I understand why it doesn’t work. My question is, can anyone suggest a reasonable way to replace the interactive shell object with something that will work?

You could use the TELNET class I wrote that is embedded in this Example App.

Xojo TELNET Class

This way you don’t have to work with any shells just the native TELNET protocol results.


Mike -
Thanks. Unfortunately, the link you supplied does not point to the file.
I’m using Putty, not telnet, but maybe I can use the technology anyway.

Sorry I forgot that I unlinked it in bitly.

Here is my Github link.
Telnet Class

It won’t help you with SSH as I am sure you know.


Why don’t you simply use shell execute to launch the BAT file that works ?

Good question. I’m investigating doing that now. Thanks.

Roland - are you calling putty or plink? I use plink to do shell-based telnet and ssh sessions in Windows.

We use shared RSA keys, so I don’t have to worry about passwords.

[quote=57713:@Mike Cotrone]Here is my Github link.
Telnet Class[/quote]

Thank you @Mike Cotrone :slight_smile:

I’m using Plink (which uses Putty, of course) and yes, it’s to avoid having to enter passwords over and over again.
Here’s the net: a Plink command, entered via the Xojo Shell, apparently works but does not return the output via the Result property. However, if instead I use the following one-line plink1.bat file:
plink %1 %2 %3 %4 %5 %6 %7 %8 %9
then when I call plink1.bat with the operands I want Plink to use, it does return the output via the Shell Result. One caveat: If I pass multiple individual strings with no imbedded blanks as the operands, it works fine; but if I pass a single string with imbedded blanks, I have to escape each blank with a preceding caret character (^).
Anyway, thanks for the help.

How have you set up the Shell? You need to set the timeout to -1 and the mode to 2:

plinkShell.Timeout = -1 plinkShell.Mode = 2 plinkShell.Execute thePlinkCommand Do App.DoEvents(20) Loop Until Not plinkShell.IsRunning If plinkShell.Errorcode <> 0 Then // handle error Else thePlinkResult = ReplaceLineEnding(plinkShell.ReadAll, EndOfLine) End If

Roland did you get plink working via the shell?

You can also echo out the “y” to automatically accept the RSA key.
Xojo Plink/SSH youtube video

Absolutely Lee. Basically you can interact intelligently via programatic recognition of the prompt being presented to the shell’s AvailableData Event by using RegEx or by assuming what the prompts are (like below).

Here is some quick and dirty forum code that works against my Cisco ASA firewall appliance using plink that I compiled for OS X. (It also works via native OS X openSSH, but I was ensuring plink could be compiled for OS X.)

(This was a desktop test app BTW)
Shell Connect Method:

  me.TimeOut = -1
  Dim LineToWrite as String = "ssh "+ ip + " -l "+uname
  Dim PLINK as String = "~mcotrone/plink  -ssh -l mcotrone "+ ip
  me.Execute PLINK
  me.writeline "Llevon33!"
  me.Write "enable"+ Chr(13) + Chr(10)
  me.writeline "ThePassswiord"
  me.Write "terminal pager 0"+ Chr(13) + Chr(10)
  me.Write "show version"+ Chr(13) + Chr(10)
  MsgBox "Running = " +str(me.IsRunning)
  MsgBox "Running = " +str(me.IsRunning)