Follow these simple steps to perform a telnet operation from a Java application:
- Download the free API, jta20.jar.
- Set the file in the classpath:
public class TestTelnet{ public static void main(String args[]){ //instantiate the telnet wrapper class TelnetWrapper telnetWrapper = new TelnetWrapper(); try { //connect to the ipaddress telnetWrapper.connect("192.168.0.xxx", 23); //username and pwd of the ipaddress telnetWrapper.login("username", "pwd"); //this is the prompt appears when doing normal ftp using cmd prompt. telnetWrapper.setPrompt("ftpprompt$"); //wait for the prompt telnetWrapper.waitfor("bash-2.03$"); //execute the commands System.out.println(telnetWrapper.send("ps -ef | grep java")); }catch(java.io.IOException e){ e.printStackTrace(); } }}