Often we come across procedures which need to be performed by issuing commands in a telnet session. Spesso venire attraverso procedure che devono essere effettuati mediante l'emissione di comandi in una sessione telnet. It is relatively easy to do it manually but is definitely not suitable for automation. È relativamente facile per farlo manualmente, ma sicuramente non è adatto per l'automazione. Let’s see how you can easily automate such tasks using Java software. Vediamo come si può facilmente automatizzare tali compiti, utilizzando il software Java. Sample code included. Codice di esempio incluso.

Here is the core code: Qui è il cuore codice:

// Conversation; Simulating telnet session with James server / / Conversazione; Simulazione sessione telnet con il server James
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, Arresto);
readLines(r, 1); readLines (r, 1);

readLines() reads and discards specified number of lines (response). readLines () legge e rigetti determinato numero di linee (risposta).

Here are the key functions: Ecco le funzioni principali:

 /** 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();     } / ** Leggi e scartare count linee da BufferedReader r * / public static void readLines (BufferedReader r, int count) lancia IOException (for (int i = 0; i <count; i + +) (String t = r.readLine (); if (debug) System.out.println (t);)) / ** Scrivi a BufferedWriter w e filo * / public static void WriteLine (BufferedWriter w, String out) lancia IOException (w.write (su + CRLF, 0 , (Su + CRLF). Lunghezza ()); w.flush ();) 

You can download the code È possibile scaricare il codice here qui . It is used to shutdown Apache James Mail Server. E 'usato per spegnere Apache James Mail Server. The utility is fully described along with the options in - L'utilità è interamente descritto insieme con le opzioni -- Shutdown Apache James Mail Server - Java Utility Arresto di Apache James server di posta - Java Utility