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

iTunes Gift Card Offer

For a limited time get a $50.00 iTunes gift card free with qualifying purchase.

Click for details.


News

JSCAPE Secure FTP Server 7.0 Released
08/20/2010 03:31 AM

JSCAPE launches Employee Giving Program
07/03/2010 08:26 AM

SSH Factory 3.6 Released
07/03/2010 06:22 AM

Secure iNet Factory 8.5 Released
07/03/2010 06:07 AM

Secure FTP Factory 8.5 Released
07/03/2010 06:03 AM

Secure FTP Applet 6.2 Released
06/10/2010 02:23 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

Open up corporate data to your partners
08/03/2010 10:01 PM

Access vital corporate documents on the go
07/01/2010 02:15 PM

SFTP and Encryption
05/17/2010 09:52 PM

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

more...


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