Advertisement
Guest User

Untitled

a guest
Jul 31st, 2012
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1. Connection.java:
  2.              try {
  3.            
  4.             /*
  5.              * we will use keyboard authentication method
  6.              */        
  7.             JSch jsch=new JSch();
  8.             Session session = jsch.getSession(msUserName, msHostName, miPort);
  9.            
  10.             /*
  11.              * set authentication object to session
  12.              */
  13.             UserInfo ui = new MyUserInfo(msUserName, msPassword);
  14.             session.setUserInfo(ui);
  15.            
  16.             /*
  17.              * throw an exception if connection can not be established in 10 seconds
  18.              */
  19.             session.setTimeout(10000);
  20.            
  21.             /*
  22.              * connect to node
  23.              */
  24.             session.connect();
  25.            
  26.             /*
  27.              * open sftp channel for file transfer
  28.              */
  29.             sftpChannel =(ChannelSftp)session.openChannel("sftp");
  30.             sftpChannel.connect();
  31.            
  32.             return true;           
  33.         } catch (JSchException e) {
  34.             return false;
  35.         } catch (Exception e) {
  36.             return false;
  37.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement