Hey all,
I'm having some issues getting a basic implementation of Jsch to work. I'm
simply trying to perform an automated (non-interactive) exec on the remote
host. The Exec.java example works fine when given the same credentials I am
passing my test class constructor (creds obscured in code below). I'm just
trying to figure out what I'm doing wrong. (Obviously this class is written in
a strange way, but it's only for proof of concept).
Here is my test code:
public class JschTest {
private JSch jsch;
private Session session = null;
private Channel ch = null;
public static void main(String[] args) {
JschTest test = new JschTest("MY_USER", "MY_PASSWORD", "HOST_IP", 22);
// LINE 35
}
public JschTest(String user, String password, String host, int port) {
jsch = new JSch();
try {
final String finPasswd = password;
session = jsch.getSession(user, host, port);
session.setUserInfo(new UserInfo() {
public String getPassphrase() { return null; }
public String getPassword() { return finPasswd; }
public boolean promptPassword(String message) { return true; }
public boolean promptPassphrase(String message) { return true; }
public boolean promptYesNo(String message) { return true; }
public void showMessage(String message) { return; }
});
session.connect();
// LINE 55
} catch (JSchException ex) {
Logger.getLogger(VMControl.class.getName()).log(Level.SEVERE, null,
ex);
}
try {
ch = session.openChannel("exec");
((ChannelExec)ch).setCommand("touch /didit");
ch.connect();
while (true) {
if (ch.isClosed()) break;
try {
Thread.sleep(1000);
} catch (InterruptedException ex) { }
}
ch.disconnect();
session.disconnect();
System.out.println("Done");
} catch (JSchException ex) {
Logger.getLogger(VMControl.class.getName()).log(Level.SEVERE, null,
ex);
}
}
}
When I run this test class I get the following error:
Jan 9, 2012 8:55:49 AM net.telestream.aptcontroller.VMControl <init>
SEVERE: null
com.jcraft.jsch.JSchException: Auth fail
at com.jcraft.jsch.Session.connect(Session.java:464)
at com.jcraft.jsch.Session.connect(Session.java:158)
at net.telestream.aptcontroller.VMControl.<init>(JschTest.java:55)
at net.telestream.aptcontroller.VMControl.main(JschTest.java:35)
I'm probably missing something basic, but could someone point out where I'm
messing this up?
Thanks,
- Ben
------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual
desktops for less than the cost of PCs and save 60% on VDI infrastructure
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
_______________________________________________
JSch-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jsch-users