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 iNet Factory 8.0 Released
04/04/2008 02:24 PM

Updates to Email Factory for .NET and Secure iNet Factory
03/29/2008 04:06 PM

JSCAPE Secure FTP Server 3.9 Preview
03/14/2008 12:19 PM

AnyClient Service and Application Launched
03/12/2008 03:41 PM

JSCAPE Secure FTP Server 3.8 Released
02/12/2008 10:50 AM


Tutorials

Email Validation with Java
04/15/2008 02:04 PM

Sending HTML Based Email Using Java
03/11/2008 02:47 PM

Secure FTP Using Java and FTPS (FTP over SSL)
03/10/2008 04:08 PM

FTP Directory Listing Using Java
03/10/2008 03:57 PM

Sending Email Using Java
03/09/2008 03:43 PM

SSH Using Java
03/09/2008 02:53 PM


Articles

DMZ File Transfer Streaming
03/28/2008 11:57 AM

Phishing looks to FTP to distribute malware
03/13/2008 05:14 PM

Ad Hoc File Transfer Explained
03/13/2008 09:16 AM

Password Policies Made Easy
03/12/2008 03:03 PM


Feedback

Request a feature or component

Request a Java or .NET component


 

Scripting Telnet Sessions using C#

This article will demonstrate how using the Telnet Factory for .NET component you can establish a non-interactive Telnet session with a TELNET server. For an introduction to using the TELNET protocol with C# see the Telnet using C# article.

To see what else Telnet Factory for .NET has to offer Download a FREE 30 day Telnet Factory for .NET Evaluation.

Overview

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

  1. Creating a new Telnet Session instance
  2. Establishing a connection
  3. Sending commands to the server
  4. Terminating the Session
  5. Releasing a connection

Each of these processes is described in the sections below.

Creating a new TelnetSession instance

Before creating a new Telnet instance, ensure that the Jscape.Telnet scope is defined in your using 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 TelnetSession instance providing the TELNET server hostname as an argument.

TelnetSession session = new TelnetSession("hostname");

Establishing a connection

Once a Telnet instance has been created you may establish a connection to the TELNET server by invoking the Connect() method providing the username and password as arguments.

session.Connect("username", "password");

Sending Commands to the server

Upon establishing a TelnetSession connection to a TELNET server the process of option negotiation automatically begins. Refer to the previous article, Telnet using C#, for more information about option negotiation.

The TelnetSession refuses 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 non-interactively with the Telnet server.

To send TelnetSession commands to the TELNET server you invoke the Send() method passing the command to execute as follows:

session.Send("ls -al");

Terminating a session

To send a command to the TELNET server without waiting for the shell prompt, invoke the SendNoWait() method as follows:

session.SendNoWait("exit");

Releasing a connection

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

session.Disconnect();

Examples

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

View example source code