Often we come across procedures which need to be performed by issuing commands in a telnet session. Muitas vezes nos deparamos com procedimentos que devem ser realizadas por meio de comandos de uma sessão telnet. It is relatively easy to do it manually but is definitely not suitable for automation. É relativamente fácil fazê-lo manualmente, mas definitivamente não é adequado para automação. Let’s see how you can easily automate such tasks using Java software. Vamos ver como você pode facilmente automatizar essa tarefa usando software Java. Sample code included. Exemplo de código incluídos.

Here is the core code: Aqui está o núcleo do código:

// Conversation; Simulating telnet session with James server / / Conversas; Simulando sessão telnet com James servidor
readLines(r, 3); readLines (r, 3);
writeLine(w, login); writeLine (w, login);
readLines(r, 1); readLines (r, 1);
writeLine(w, password); writeLine (w, password);
readLines(r, 1); readLines (r, 1);
writeLine(w, SHUTDOWN); writeLine (w, SHUTDOWN);
readLines(r, 1); readLines (r, 1);

readLines() reads and discards specified number of lines (response). readLines () lê e devoluções determinado número de linhas (resposta).

Here are the key functions: Aqui estão as principais funções:

 /** Read and discard count lines from BufferedReader r */     public static void readLines(BufferedReader r, int count) throws IOException {         for(int i = 0;i < count;i++) {             String t = r.readLine();             if(DEBUG) System.out.println(t);         }     }      /** Write out to BufferedWriter w and flush */     public static void writeLine(BufferedWriter w, String out) throws IOException {         w.write(out + CRLF, 0, (out + CRLF).length());         w.flush();     } / ** Ler e descartar conta as linhas de BufferedReader r * / public static void readLines (BufferedReader r, int count) throws IOException (for (int i = 0; i <count; i + +) (String t = r.readLine (); if (DEBUG) System.out.println (t);)) / ** Escreve-se BufferedWriter w e flush * / public static void writeLine (BufferedWriter w, String out) throws IOException (w.write (out + CRLF, 0 , (A + CRLF). Comprimento ()); w.flush ();) 

You can download the code Você pode fazer o download do código here aqui . It is used to shutdown Apache James Mail Server. É usado para shutdown Apache James Mail Server. The utility is fully described along with the options in - O utilitário é descrito na íntegra, juntamente com as opções em -- Shutdown Apache James Mail Server - Java Utility Encerrar Apache James servidor de e-mail - Java Utility