mardi 4 août 2015

Jsch Shell won't accept input from Terminal

I have written a simple groovy program that uses the Jsch Library to establish an ssh tunnel and open a shell on the target server. The script connect fine and the shell opens. In IntelliJ I can enter input into the shell and get the subsequent output if I run the program. However if I attempt to do the same in the Terminal or in a cmd it connects fine but I cannot enter any input so can't run commands.

println "Opening connection to ${sshUser}@${sshHost}:${sshPort}"
Properties config = new Properties()
config.put("StrictHostKeyChecking", "no")
JSch jsch = new JSch()

Session sshSession = jsch.getSession(sshUser, sshHost, sshPort as int)
sshSession.setPassword(sshPass)
sshSession.setConfig(config)
sshSession.connect()
println "Connected"


println "Forwarding connection to ${targetHost}:${targetPort}"
def assignedPort = sshSession.setPortForwardingL(0, targetHost, targetPort as int)
println "Got port $assignedPort"

// Set the session to open as a Shell
Channel channel = targetSession.openChannel("shell")
// Set Input and Output streams
channel.setInputStream(System.in)
channel.setOutputStream(System.out);
// Connect
channel.connect()



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire