Guest User

Untitled

a guest
Oct 14th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. public class SshConector {
  2.  
  3. //variables
  4. protected String host, user, password, consoleMessage; //variables to connect
  5. protected Session session;
  6. protected int port=22; //ssh port
  7. //ssh connection
  8. private JSch jschChannel;
  9. private int intTimeOut = 60000; //timeout for connection
  10.  
  11.  
  12. public SshConector(String hostE, String userE, String passwordE) {
  13. host = hostE;
  14. user = userE;
  15. password = passwordE;
  16. intTimeOut = 60000; //timeout by default
  17. jschChannel = new JSch();
  18. }//end constructor
  19.  
  20. public SshConector() {
  21. }
  22.  
  23. public boolean connect() {
  24. try {
  25. session = jschChannel.getSession(user, host, port);
  26. session.setPassword(password);
  27. // Avoid asking for key confirmation
  28. Properties prop = new Properties();
  29. prop.put("StrictHostKeyChecking", "no");
  30. session.setConfig(prop);
  31. //start
  32. session.connect(intTimeOut);
  33. return true; //connection correctly
  34. }catch (JSchException e) {
  35. e.printStackTrace();
  36. Log.i("INFO_SESSION","Error: "+ e.getMessage());
  37. return false; //error
  38. }/* catch (NetworkOnMainThreadException ex) {
  39. return false;
  40. }*/
  41. }//connect with the server
  42.  
  43. public void setTimeOutConnection(int timeOut) {
  44. intTimeOut = timeOut;
  45. }//end
  46.  
  47. public long getTimeOut() {
  48. return intTimeOut;
  49. }//get the timeout to connect
  50.  
  51. public String getHost() {
  52. return host;
  53. }
  54.  
  55. public void setHost(String host) {
  56. this.host = host;
  57. }
  58.  
  59. public String getUser() {
  60. return user;
  61. }
  62.  
  63. public void setUser(String user) {
  64. this.user = user;
  65. }
  66.  
  67. public String getPassword() {
  68. return password;
  69. }
  70.  
  71. public void setPassword(String password) {
  72. this.password = password;
  73. }
  74.  
  75. public String getConsoleMessage() {
  76. return consoleMessage;
  77. }
  78.  
  79. public void setIntTimeOut(int intTimeOut) {
  80. this.intTimeOut = intTimeOut;
  81. }
  82.  
  83. }//end of class
Add Comment
Please, Sign In to add comment