Skip to content

Package: SshSession

SshSession

nameinstructionbranchcomplexitylinemethod
SshSession(String, String, String, int)
M: 41 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
SshSession(String, String, int, String)
M: 41 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
SshSession(String, String, int, String, String)
M: 42 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
connect()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
disconnect()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getSession()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: package update.remote.ssh;
2:
3: import com.jcraft.jsch.JSch;
4: import com.jcraft.jsch.JSchException;
5: import com.jcraft.jsch.Session;
6: import com.jcraft.jsch.UserInfo;
7:
8: /**
9: * The Session handler.
10: *
11: * @author Muri
12: *
13: */
14: public class SshSession {
15:
16:         /**
17:          * No.
18:          */
19:         private static final String NOO = "no";
20:         /**
21:          * Variable to set Host Key Checking.
22:          */
23:         private static final String HOST_KEY_CHECKING = "StrictHostKeyChecking";
24:         /**
25:          *
26:          */
27:         private final transient JSch jsch = new JSch();
28:         /**
29:          *
30:          */
31:         private final transient Session session;
32:
33:         /**
34:          *
35:          * @param user
36:          * user
37:          * @param host
38:          * host
39:          * @param port
40:          * port
41:          * @param path
42:          * path
43:          * @throws JSchException
44:          * exception
45:          */
46:         public SshSession(final String user, final String host, final int port, final String path)
47:                         throws JSchException {
48:                 super();
49:                 this.jsch.addIdentity(path);
50:                 this.session = this.jsch.getSession(user, host, port);
51:                 // System.out.println(this.session.);
52:                 final UserInfo mui = new MyUserInfo();
53:                 this.session.setUserInfo(mui);
54:                 final java.util.Properties config = new java.util.Properties(); // NOPMD ThreadGroup is not
55:                                                                                                                                                 // used! Seems to be a bug
56:                                                                                                                                                 // in PMD
57:                 config.put(HOST_KEY_CHECKING, NOO);
58:                 this.session.setConfig(config);
59:         }
60:
61:         /**
62:          *
63:          * @param user
64:          * user
65:          * @param host
66:          * host
67:          * @param port
68:          * port
69:          * @param path
70:          * path
71:          * @param passphrase
72:          * passphrase
73:          * @throws JSchException
74:          * exception
75:          */
76:         public SshSession(final String user, final String host, final int port, final String path,
77:                         final String passphrase) throws JSchException {
78:                 super();
79:                 this.jsch.addIdentity(path, passphrase);
80:                 this.session = this.jsch.getSession(user, host, port);
81:                 // System.out.println(this.session.);
82:                 final UserInfo mui = new MyUserInfo();
83:                 this.session.setUserInfo(mui);
84:                 final java.util.Properties config = new java.util.Properties(); // NOPMD ThreadGroup is not
85:                                                                                                                                                 // used! Seems to be a bug
86:                                                                                                                                                 // in PMD
87:                 config.put(HOST_KEY_CHECKING, NOO);
88:                 this.session.setConfig(config);
89:         }
90:
91:         /**
92:          *
93:          * @param user
94:          * user
95:          * @param host
96:          * host
97:          * @param port
98:          * port
99:          * @param password
100:          * password
101:          * @throws JSchException
102:          * exception
103:          */
104:         public SshSession(final String user, final String password, final String host, final int port)
105:                         throws JSchException {
106:                 super();
107:                 this.session = this.jsch.getSession(user, host, port);
108:                 this.session.setPassword(password);
109:                 final UserInfo mui = new MyUserInfo();
110:                 this.session.setUserInfo(mui);
111:                 final java.util.Properties config = new java.util.Properties(); // NOPMD ThreadGroup is not
112:                                                                                                                                                 // used! Seems to be a bug
113:                                                                                                                                                 // in PMD
114:                 config.put(HOST_KEY_CHECKING, NOO);
115:                 this.session.setConfig(config);
116:         }
117:
118:         /**
119:          * pass through connect method.
120:          *
121:          * @throws JSchException
122:          * JSchException
123:          */
124:         public void connect() throws JSchException {
125:                 this.session.connect();
126:         }
127:
128:         /**
129:          * pass through disconnect method.
130:          */
131:         public void disconnect() {
132:                 this.session.disconnect();
133:         }
134:
135:         /**
136:          * get the session.
137:          *
138:          * @return Session session
139:          */
140:         public Session getSession() {
141:                 return this.session;
142:         }
143:
144: }