1 11 package org.eclipse.jsch.internal.core; 12 13 import org.eclipse.core.runtime.IProgressMonitor; 14 import org.eclipse.jsch.core.IJSchService; 15 16 import com.jcraft.jsch.*; 17 18 23 public class JSchProvider implements IJSchService { 24 25 private static JSchProvider instance; 26 27 30 public Session createSession(String host, int port, String username) throws JSchException { 31 if(port == -1) 32 port = IConstants.SSH_DEFAULT_PORT; 33 34 if(JSchCorePlugin.getPlugin().isNeedToLoadKnownHosts()){ 35 JSchCorePlugin.getPlugin().loadKnownHosts(); 36 } 37 38 if(JSchCorePlugin.getPlugin().isNeedToLoadKeys()){ 39 JSchCorePlugin.getPlugin().loadPrivateKeys(); 40 } 41 42 return Utils.createSession(JSchCorePlugin.getPlugin().getJSch(), username, host, port); 43 } 44 45 48 public void connect(Session session, int timeout, 49 IProgressMonitor monitor) throws JSchException{ 50 session.setSocketFactory(new ResponsiveSocketFactory(monitor, timeout)); 51 try{ 52 session.connect(); 53 } 54 catch(JSchException e){ 55 if(session.isConnected()) 56 session.disconnect(); 57 throw e; 58 } 59 } 60 61 64 public Proxy getProxyForHost(String host, String proxyType) { 65 return Utils.getProxyForHost(host, proxyType); 66 } 67 68 public static IJSchService getInstance(){ 69 if (instance == null) 70 instance = new JSchProvider(); 71 return instance; 72 } 73 74 77 public void connect(Proxy proxy, String host, int port, int timeout, 78 IProgressMonitor monitor) throws JSchException { 79 try{ 80 proxy.connect(new ResponsiveSocketFactory(monitor, timeout), host, port, timeout); 81 } 82 catch(JSchException e){ 83 throw e; 84 } 85 catch(Exception e){ 86 new JSchException(e.getMessage()); 87 } 88 } 89 90 } 91 | Popular Tags |