private void connect(String ip, int port, String user, String key, String passphrase, Proxy proxy) throws JSchException { jsch = new JSch(); jsch.addIdentity(key); session = jsch.getSession(user, ip, port); if (proxy != null) { if ("HTTP".equalsIgnoreCase(proxy.getType())) { session.setProxy(new ProxyHTTP(proxy.getProxyIp(), proxy.getProxyPort())); } else if ("SOCKS5".equalsIgnoreCase(proxy.getType())) { session.setProxy(new ProxySOCKS5(proxy.getProxyIp(), proxy.getProxyPort())); } else if ("SOCKS4".equalsIgnoreCase(proxy.getType())) { session.setProxy(new ProxySOCKS4(proxy.getProxyIp(), proxy.getProxyPort())); } } session.setUserInfo(new MyUserInfo(null, passphrase)); Properties conf = new Properties(); conf.put("StrictHostKeyChecking", "no"); session.setConfig(conf); synchronized (JSch.class) { session.connect(timeout); } }
public void setProxySOCKS4(String proxy_host, int proxy_port, String proxy_user, String proxy_password){ proxySOCKS4 = new ProxySOCKS4(proxy_host, proxy_port); if (proxy_user!=null) proxySOCKS4.setUserPasswd(proxy_user, proxy_password); proxyType=SOCKS4; if (myLogger!=null) myLogger.log(com.jcraft.jsch.Logger.DEBUG, "PROXY_SOCKS4 host="+proxy_host+"; port="+proxy_port+"; user="+proxy_user); }
public Response<String> connect(String ip,int port,String user,String passwd, Proxy proxy){ Response<String> resp = new Response<String>(); try { jsch = new JSch(); session = jsch.getSession(user, ip, port); if (proxy != null) { if ("HTTP".equalsIgnoreCase(proxy.getType())) { session.setProxy(new ProxyHTTP(proxy.getProxyIp(), proxy.getProxyPort())); } else if ("SOCKS5".equalsIgnoreCase(proxy.getType())) { session.setProxy(new ProxySOCKS5(proxy.getProxyIp(), proxy.getProxyPort())); } else if ("SOCKS4".equalsIgnoreCase(proxy.getType())) { session.setProxy(new ProxySOCKS4(proxy.getProxyIp(), proxy.getProxyPort())); } } session.setPassword(passwd); Properties conf = new Properties(); conf.put("StrictHostKeyChecking", "no"); session.setConfig(conf); session.connect(); ftps = (ChannelSftp) session.openChannel("sftp"); ftps.connect(); resp.setCode(Response.OK); connected = true; } catch (JSchException e) { resp.setCode(Response.IO_EXCEPTION); resp.setPhrase("SftpException: " + e.getMessage()); } return resp; }
public Response<String> connect(String ip,int port,String user,String key,String passphrase, Proxy proxy) { Response<String> resp = new Response<String>(); try { jsch = new JSch(); jsch.addIdentity(key); session = jsch.getSession(user, ip, port); if (proxy != null) { if ("HTTP".equalsIgnoreCase(proxy.getType())) { session.setProxy(new ProxyHTTP(proxy.getProxyIp(), proxy.getProxyPort())); } else if ("SOCKS5".equalsIgnoreCase(proxy.getType())) { session.setProxy(new ProxySOCKS5(proxy.getProxyIp(), proxy.getProxyPort())); } else if ("SOCKS4".equalsIgnoreCase(proxy.getType())) { session.setProxy(new ProxySOCKS4(proxy.getProxyIp(), proxy.getProxyPort())); } } session.setUserInfo(new MyUserInfo(null,passphrase)); Properties conf = new Properties(); conf.put("StrictHostKeyChecking", "no"); session.setConfig(conf); session.connect(); ftps = (ChannelSftp) session.openChannel("sftp"); ftps.connect(); connected = true; resp.setCode(Response.OK); } catch (JSchException e) { resp.setCode(Response.IO_EXCEPTION); resp.setPhrase("SftpException: " + e.getMessage()); } return resp; }
private void connect(String ip, int port, String user, String passwd, Proxy proxy) throws JSchException { jsch = new JSch(); session = jsch.getSession(user, ip, port); session.setPassword(passwd); if (proxy != null) { if ("HTTP".equalsIgnoreCase(proxy.getType())) { session.setProxy(new ProxyHTTP(proxy.getProxyIp(), proxy.getProxyPort())); } else if ("SOCKS5".equalsIgnoreCase(proxy.getType())) { session.setProxy(new ProxySOCKS5(proxy.getProxyIp(), proxy.getProxyPort())); } else if ("SOCKS4".equalsIgnoreCase(proxy.getType())) { session.setProxy(new ProxySOCKS4(proxy.getProxyIp(), proxy.getProxyPort())); } } Properties conf = new Properties(); conf.put("StrictHostKeyChecking", "no"); session.setConfig(conf); synchronized (JSch.class) { session.connect(timeout); } }