Java and .NET components, FTP, TELNET, SMTP, POP3, IMAP, HTTP, SSH
Home Search Knowledge Base Support

Support

Click here for access to live sales support.

For technical support please submit a ticket to the Help Desk.

 

Java and .NET Help

iPod shuffle offer

For a limited time get the newly re-designed iPod shuffle free with qualifying purchase.

Click for details.


News

Secure FTP Factory 8.4 Released
03/11/2010 09:55 AM

Secure iNet Factory 8.4 Released
03/11/2010 09:52 AM

JSCAPE Secure FTP Server 6.4 Released
01/18/2010 03:58 PM

JSCAPE Secure FTP Server 6.3 Released
12/14/2009 05:45 PM

Secure iNet Factory 8.3.1 Released
12/04/2009 04:26 PM

SSH Factory 3.5 Released
11/10/2009 01:46 PM

more...


Tutorials

Enabling Phone Authentication
04/08/2009 11:24 AM

Detecting and Handling Brute Force Password Attacks
01/29/2009 09:44 AM

Creating a Domain
12/15/2008 11:33 AM

Public key authentication with SFTP
10/02/2008 07:59 AM

Formatting MimeMessages using .NET
09/14/2008 04:31 PM

Communicating with an IMAP4 server in .NET
09/14/2008 03:54 PM

more...


Articles

Streamlining web uploads with ZIP archives
12/14/2009 10:11 AM

Using regular expressions in complex trigger conditions
09/08/2009 07:42 AM

Using custom forms to automate business processes
07/03/2009 08:51 AM

Public key authentication with SFTP
10/02/2008 07:59 AM

Best Practices for Configuring Your FTP Server
06/03/2008 04:47 PM

What is the difference between passive and active FTP?
05/20/2008 09:27 AM

more...


Feedback

Request a feature or component

Request a Java or .NET component


 

Telnet using VB

This article will demonstrate how using the Telnet Factory for .NET component you can establish an interactive Telnet session with a TELNET server using Visual Basic. This article compliments the Telnet using C# article previously released. To see what else Telnet Factory for .NET has to offer Download a FREE 30 day Telnet Factory for .NET Evaluation.


Overview of Telnet

The Telnet Factory for .NET component provides a method for communicating with a TELNET server. The process for establishing an interactive session with a TELNET server using the Telnet Factory for .NET component is as follows:

  1. Creating a new Telnet instance
  2. Define Telnet Event Handler methods
  3. Establishing a connection
  4. Performing option negotiation
  5. Receiving data
  6. Sending data
  7. Releasing a connection

Each of these processes is described in the sections below.


Creating a new Telnet instance

Before creating a new Telnet instance, ensure that the Jscape.Telnet scope is defined in your imports statements, and that the Jscape.Telnet.dll is referenced in your project. Refer to Getting Started in the Telnet Factory for .NET Help for more information about adding the Jscape.Telnet.dll reference to your projects.

Create a new Telnet instance providing the TELNET server hostname as an argument.

myTelnet = New Telnet("hostname")


Subscribing to Telnet Events

The Telnet instance subscribes to the Telnet events using the WithEvents keyword. This is necessary prior to invoking the Connect() method to ensure that all data sent by the TELNET server is captured. See Receiving data later in this article for more information about processing this event.

Public WithEvents myTelnet As Telnet

Now you create the event handler methods for each of the Telnet events. See Performing option negotiation later in this article for more information about capturing and processing option negotiation events.

Public Sub OnConnected(ByVal sender As Object, ByVal e As TelnetConnectedEventArgs) Handles myTelnet.ConnectedEvent
   ' Tell user we are connected.
   Console.WriteLine("Connected to {0}:{1}", e.Host, e.Port)
End Sub

Private Sub OnDisconnected(ByVal sender As Object, ByVal e As TelnetDisconnectedEventArgs) Handles myTelnet.DisconnectedEvent
   ' Tell user we disconnected.
   Console.WriteLine("Disconnected.")
End Sub


Establishing a connection

Once a Telnet instance has been created you may establish a connection to the TELNET server by invoking the Connect() method.

myTelnet.Connect();


Performing option negotiation

Upon establishing a connection to a TELNET server the process of option negotiation automatically begins. Option negotiation is a communications process for the Telnet client and the Telnet server to come up with a set of agreed upon protocols. An example of option negotiation is agreeing upon the terminal emulation (e.g. vt100, xterm, dumb) to use during the Telnet session.

Option negotiation, as its name implies, is optional and may be initiated by either the client or server. This does not mean, however, that option negotiation may be ignored. For example, in the event that the server attempts to perform option negotiation the client must respond by either accepting or rejecting the option request. Capturing option negotiation data from the Telnet server is accomplished using the option event handlers.

In performing option negotiation there are four (4) Telnet protocol commands that can be used by the client and server.

  1. DO OPTION - Requests to enable an option.
  2. DONT OPTION - Refuses offer to enable an option.
  3. WILL OPTION - Offers to enable an option.
  4. WONT OPTION - Refuses request to enable an option.

For the purposes of this article we will refuse all options both requested and offered by the TELNET server. This, in effect, will give us a basic Telnet client that is capable of exchanging data with the Telnet server. In order to capture and refuse options requested or offered by the Telnet server you will need to create the option event handler methods as follows:

Private Sub OnDoOption(ByVal sender As Object, ByVal e As TelnetDoOptionEventArgs) Handles myTelnet.DoOptionEvent
   myTelnet.SendWontOption(e.Option)
End Sub

Private Sub OnDontOption(ByVal sender As Object, ByVal e As TelnetDontOptionEventArgs) Handles myTelnet.DontOptionEvent
   myTelnet.SendDontOption(e.Option)
End Sub

Private Sub OnWillOption(ByVal sender As Object, ByVal e As TelnetWillOptionEventArgs) Handles myTelnet.WillOptionEvent
   myTelnet.SendDontOption(e.Option)
End Sub

Private Sub OnWontOption(ByVal sender As Object, ByVal e As TelnetWontOptionEventArgs) Handles myTelnet.WontOptionEvent
   myTelnet.SendWontOption(e.Option)
End Sub


Receiving data

Once option negotiation has been completed, you may begin receiving data sent by the TELNET server. To capture and display data received from the TELNET server, create a data received event method as follows:

Private Sub OnDataReceived(ByVal sender As Object, ByVal e As TelnetDataReceivedEventArgs) Handles myTelnet.DataReceivedEvent
   ' Write characters of byte data received from TELNET server using default encoding (UTF8)
   Console.Write(myTelnet.Encoding.GetString(e.Data))
End Sub


Sending data

To send data to the TELNET server you first obtain a TelnetOutputStream from the Telnet instance. You can then send data to the Telnet server from the console as follows:

' Begin reading and writing data to telnet server
Dim output As TelnetOutputStream = myTelnet.GetOutputStream()
Dim input As String = ""
Do
   input = Console.ReadLine()
   If (input <> "exit") Then
      output.PrintLn(input)
   Else
      Me.Connected = False
   End If
Loop While Me.Connected = True


In the example above the input comes from the console and is redirected to the TELNET server using the PrintLn() method. The TelnetOutputStream class is used as it automatically appends a \r\n (carriage return line feed) to the data. This is required by the Telnet server for it to know when it may begin processing the data received.


Releasing a connection

To release an established connection simply invoke the Disconnect() method as follows:

myTelnet.Disconnect();


Examples

The source code for this article is available for download and for viewing.

View example source code