]>
git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/jsch/AbstractJschTask.java
8a58c357f9b85978b69988a477e84fc158ede3de
1 package org
.argeo
.slc
.jsch
;
3 import java
.io
.IOException
;
4 import java
.io
.InputStream
;
6 import org
.argeo
.slc
.SlcException
;
8 import com
.jcraft
.jsch
.JSch
;
9 import com
.jcraft
.jsch
.JSchException
;
10 import com
.jcraft
.jsch
.Session
;
12 public abstract class AbstractJschTask
implements Runnable
{
13 private SshTarget sshTarget
;
15 protected Session
openSession() {
17 JSch jsch
= new JSch();
18 if (sshTarget
.getUsePrivateKey()
19 && sshTarget
.getLocalPrivateKey().exists())
20 jsch
.addIdentity(sshTarget
.getLocalPrivateKey()
22 Session session
= jsch
.getSession(getSshTarget().getUser(),
23 getSshTarget().getHost(), getSshTarget().getPort());
25 session
.setUserInfo(getSshTarget().getUserInfo());
28 } catch (JSchException e
) {
29 throw new SlcException("Could not open session to "
34 public final void run() {
35 Session session
= openSession();
43 abstract void run(Session session
);
45 protected int checkAck(InputStream in
) throws IOException
{
47 // b may be 0 for success,
54 return b
;// throw new SlcException("SSH ack returned -1");
55 else if (b
== 1 || b
== 2) {
56 StringBuffer sb
= new StringBuffer();
62 if (b
== 1) { // error
63 throw new SlcException("SSH ack error: " + sb
.toString());
65 if (b
== 2) { // fatal error
66 throw new SlcException("SSH fatal error: " + sb
.toString());
72 public SshTarget
getSshTarget() {
73 if (sshTarget
== null)
74 throw new SlcException("No SSH target defined.");
78 public void setSshTarget(SshTarget sshTarget
) {
79 this.sshTarget
= sshTarget
;