Hello,


For the past day I have been trying  to make the SSHD Client work with the
Expect library without any success. I was wondering if anyone has managed
to make it work?

I have tried using these two implementations of Expect (
https://github.com/ronniedong/Expect-for-Java &
http://code.google.com/p/expect4j/)

Here is an example:

https://github.com/ronniedong/Expect-for-Java/issues/3

----------------------------------------------
import org.apache.sshd.*

SshClient client = SshClient.setUpDefaultClient()
ClientSession session = client.connect(host, port).await().getSession()
session.authPassword(user, password).await().isSuccess()
ClientChannel channel = session.createChannel(ClientChannel.CHANNEL_SHELL)

channel.setIn(new ByteArrayInputStream())
channel.setOut(new ByteArrayOutputStream())
channel.setErr(new ByteArrayOutputStream())
channel.open()

Expect expect = new Expect(channel.getIn(), channel.getOut())
expect.send("ls\n")
expect.expect("$")

expect.send("exit\n")
expect.expectEOF()
expect.close()

channel.waitFor(ClientChannel.CLOSED, 0)
channel.close(false)
client.stop()
----------------------------------------------


Thanks in advanced for any help.

Reply via email to