Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

SSH Connection  RSS feed

 
Daniel Martins
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

I am trying to connect via SSH using the following code:



I am getting a "Connection Sucessfull".

What I would like to know is hoiw to send linux commands like "ls -ltr"?

Cheers
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Although you're connecting to the port, any attempt to send data will result in the connection being dropped. The socket you've connected to is expecting data in the encrypted SSH protocol (in fact, it's first expecting a complicated exchange during which encryption and security options are negotiated.)

To accomplish what you want, you need to use an SSH library. There are quite a few to choose from: JSch is a particular one that I have experience with.
 
Daniel Martins
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the info. Tomorrow i will give it a try
 
Daniel Martins
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I just installed it and....first glimpse...gives me the feeling that it´s a bit complex/overloaded...

I have to say that it got me lost, i was looking for "simple" connect, authenticate, write (send commands), read operations...

Does Java has any API that enable this?

Thanks
 
Daniel Martins
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, small update. The Shell.java seems (theoretically) to do the connection

As for the other operation I will have to look more!

I can only try this tomorrow since the server I want to connect is at work..

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!