The Telnet library will let you interact with a host using the Telnet protocol. You can send any command and get the data that is returned by it. It is also possible to react on various events that are triggered.

My personal favorite is a ‘tail -f’ command on a log file. This will look like the host is triggering an event in your Visual Basic application when something is added to the log file. I have such an application running in my Windows service for months.

Click here to download the complete source code, the compiled DLL and the demo.

Below you can see all the code that you need when you want to execute a command on a remote machine:

Public WithEvents Telnet As Telnet
Private Sub btnStart_Click()
   Set Telnet = New Telnet
   Telnet.TelnetHost = "mytelnethost.com"
   Telnet.TelnetPort = 23
   Telnet.UserName = :MyUsername"
   Telnet.Password = "MySecretPassword"
   Telnet.LoginPrompt = "$"
   Telnet.PassWordPrompt = "Password:"
   Telnet.Prompt = vbLf & "$"
   Telnet.Login
   Telnet.Command "ls -l"
   Telnet.Logout
   Set Telnet = Nothing
End Sub

Private Sub Telnet_LineReceived(strData As String)
  ' Put here code to process the data for the command.
  Debug.Print strData
  ' Just clear the buffer after each line so that we
  ' will not use more memory than neccessery.
  Telnet.ReceivedData = ""
End Sub
  • Share/Bookmark