jaireltonPJ 23 de jun. de 2005
Dá uma olhada na API Jakarta Commons Net.
http://jakarta.apache.org/commons/net/
samuraiPJ 29 de jun. de 2005
E aí pessoal beleza?
Estou tentando fazer uma conexão por telnet usando a commons-net do jakarta mas está me retornando o seguinte erro:
SSH-1.99-OpenSSH_3.6.1p2
O estranho é que to usando a classe TelnetCliente e dá um erro falando sobre ssh.
Aí vai o código:
public class ConexaoTELNET & #123 ;
private TelnetClient telnet = null ;
private InputStream in ;
private PrintStream out ;
private ConexaoBean conexao = null ;
public ConexaoTELNET & #40 ;) {
telnet = new TelnetClient & #40 ;);
& #125 ;
public void getConexao & #40 ; Object bean){
conexao = & #40 ;ConexaoBean)bean;
try & #123 ;
// Conex ão com o servidor
telnet .connect & #40 ; conexao.getHost(), conexao.getPorta() );
// Entrada e saida de parametros
in = telnet .getInputStream & #40 ;);
out = new PrintStream & #40 ;telnet.getOutputStream());
& #125 ;
catch & #40 ; Exception e ) {
e .printStackTrace & #40 ;);
& #125 ;
& #125 ;
public String getComando & #40 ;String comando){
String retorno = null ;
try & #123 ;
int ii = 0 ;
byte & #91 ;] tmp = new byte[1024];
out .println & #40 ;comando);
out .flush & #40 ;);
while & #40 ;in.available() > 0) {
int i = in .read & #40 ;tmp, 0, 1024);
if & #40 ;i < 0)
break ;
ii = i ;
retorno += new String & #40 ;tmp, 0, i);
& #125 ;
& #125 ;catch(IOException e){
e .printStackTrace & #40 ;);
& #125 ;
return retorno ;
& #125 ;
public void disconnect & #40 ;) {
try & #123 ;
telnet .disconnect & #40 ;);
& #125 ;
catch & #40 ; Exception e ) {
e .printStackTrace & #40 ;);
& #125 ;
& #125 ;
& #125 ;
Desde já gradeço!
samuraiPJ 29 de jun. de 2005
Foi mau!!! :oops: :oops: :oops: :oops:
Que puta navalhada!!! :oops: :oops: :oops: :oops:
Eu estava conectando na porta 22 ao invés de 23!!
[b]
Red Hat Enterprise Linux AS release 3 (Taroon)
Kernel 2.4.21-4.ELsmp on an i686
login:
[/b]
Deveria me dar um retorno de ls -h que foi o comando que passei.
Obrigado! :