Search in sources :

Example 1 with Proxy

use of com.jcraft.jsch.Proxy in project javautils by jiadongpo.

the class SFTPClient method setProxy.

public void setProxy(String host, String port, String user, String pass, String proxyType) throws Exception {
    if (isEmpty(host) || toInt(port, 0) == 0) {
        throw new Exception("Proxy server name must be set and server port must be greater than zero.");
    }
    Proxy proxy = null;
    String proxyhost = host + ":" + port;
    if (proxyType.equals(PROXY_TYPE_HTTP)) {
        proxy = new ProxyHTTP(proxyhost);
        if (!isEmpty(user)) {
            ((ProxyHTTP) proxy).setUserPasswd(user, pass);
        }
    } else if (proxyType.equals(PROXY_TYPE_SOCKS5)) {
        proxy = new ProxySOCKS5(proxyhost);
        if (!isEmpty(user)) {
            ((ProxySOCKS5) proxy).setUserPasswd(user, pass);
        }
    }
    s.setProxy(proxy);
}
Also used : Proxy(com.jcraft.jsch.Proxy) ProxySOCKS5(com.jcraft.jsch.ProxySOCKS5) ProxyHTTP(com.jcraft.jsch.ProxyHTTP) FileSystemException(org.apache.commons.vfs2.FileSystemException) IOException(java.io.IOException) SftpException(com.jcraft.jsch.SftpException) JSchException(com.jcraft.jsch.JSchException)

Example 2 with Proxy

use of com.jcraft.jsch.Proxy in project javautils by jiadongpo.

the class SFTPClient method setProxy.

public void setProxy(String host, String port, String user, String pass, String proxyType) throws Exception {
    if (isEmpty(host) || toInt(port, 0) == 0) {
        throw new Exception("Proxy server name must be set and server port must be greater than zero.");
    }
    Proxy proxy = null;
    String proxyhost = host + ":" + port;
    if (proxyType.equals(PROXY_TYPE_HTTP)) {
        proxy = new ProxyHTTP(proxyhost);
        if (!isEmpty(user)) {
            ((ProxyHTTP) proxy).setUserPasswd(user, pass);
        }
    } else if (proxyType.equals(PROXY_TYPE_SOCKS5)) {
        proxy = new ProxySOCKS5(proxyhost);
        if (!isEmpty(user)) {
            ((ProxySOCKS5) proxy).setUserPasswd(user, pass);
        }
    }
    s.setProxy(proxy);
}
Also used : Proxy(com.jcraft.jsch.Proxy) ProxySOCKS5(com.jcraft.jsch.ProxySOCKS5) ProxyHTTP(com.jcraft.jsch.ProxyHTTP) FileSystemException(org.apache.commons.vfs2.FileSystemException) IOException(java.io.IOException) SftpException(com.jcraft.jsch.SftpException) JSchException(com.jcraft.jsch.JSchException)

Example 3 with Proxy

use of com.jcraft.jsch.Proxy in project pentaho-kettle by pentaho.

the class SFTPClient method setProxy.

public void setProxy(String host, String port, String user, String pass, String proxyType) throws KettleJobException {
    if (Utils.isEmpty(host) || Const.toInt(port, 0) == 0) {
        throw new KettleJobException("Proxy server name must be set and server port must be greater than zero.");
    }
    Proxy proxy = null;
    String proxyhost = host + ":" + port;
    if (proxyType.equals(PROXY_TYPE_HTTP)) {
        proxy = new ProxyHTTP(proxyhost);
        if (!Utils.isEmpty(user)) {
            ((ProxyHTTP) proxy).setUserPasswd(user, pass);
        }
    } else if (proxyType.equals(PROXY_TYPE_SOCKS5)) {
        proxy = new ProxySOCKS5(proxyhost);
        if (!Utils.isEmpty(user)) {
            ((ProxySOCKS5) proxy).setUserPasswd(user, pass);
        }
    }
    s.setProxy(proxy);
}
Also used : Proxy(com.jcraft.jsch.Proxy) ProxySOCKS5(com.jcraft.jsch.ProxySOCKS5) ProxyHTTP(com.jcraft.jsch.ProxyHTTP) KettleJobException(org.pentaho.di.core.exception.KettleJobException)

Example 4 with Proxy

use of com.jcraft.jsch.Proxy in project javautils by jiadongpo.

the class SFTPClient method setProxy.

public void setProxy(String host, String port, String user, String pass, String proxyType) throws Exception {
    if (isEmpty(host) || toInt(port, 0) == 0) {
        throw new Exception("Proxy server name must be set and server port must be greater than zero.");
    }
    Proxy proxy = null;
    String proxyhost = host + ":" + port;
    if (proxyType.equals(PROXY_TYPE_HTTP)) {
        proxy = new ProxyHTTP(proxyhost);
        if (!isEmpty(user)) {
            ((ProxyHTTP) proxy).setUserPasswd(user, pass);
        }
    } else if (proxyType.equals(PROXY_TYPE_SOCKS5)) {
        proxy = new ProxySOCKS5(proxyhost);
        if (!isEmpty(user)) {
            ((ProxySOCKS5) proxy).setUserPasswd(user, pass);
        }
    }
    s.setProxy(proxy);
}
Also used : Proxy(com.jcraft.jsch.Proxy) ProxySOCKS5(com.jcraft.jsch.ProxySOCKS5) ProxyHTTP(com.jcraft.jsch.ProxyHTTP) FileSystemException(org.apache.commons.vfs2.FileSystemException) IOException(java.io.IOException) SftpException(com.jcraft.jsch.SftpException) JSchException(com.jcraft.jsch.JSchException)

Example 5 with Proxy

use of com.jcraft.jsch.Proxy in project spring-integration by spring-projects.

the class ProxyTests method testFactoryBean.

@Test
public void testFactoryBean() throws Exception {
    JschProxyFactoryBean proxyFactoryBean = new JschProxyFactoryBean(JschProxyFactoryBean.Type.SOCKS5, "localhost", 1080, "ftptest", "pass");
    proxyFactoryBean.afterPropertiesSet();
    Proxy proxy = proxyFactoryBean.getObject();
    assertProxy(proxy, ProxySOCKS5.class);
    proxyFactoryBean = new JschProxyFactoryBean(JschProxyFactoryBean.Type.SOCKS4, "localhost", 1080, "ftptest", "pass");
    proxyFactoryBean.afterPropertiesSet();
    proxy = proxyFactoryBean.getObject();
    assertProxy(proxy, ProxySOCKS4.class);
    proxyFactoryBean = new JschProxyFactoryBean(JschProxyFactoryBean.Type.HTTP, "localhost", 1080, "ftptest", "pass");
    proxyFactoryBean.afterPropertiesSet();
    proxy = proxyFactoryBean.getObject();
    assertProxy(proxy, ProxyHTTP.class);
}
Also used : Proxy(com.jcraft.jsch.Proxy) Test(org.junit.Test)

Aggregations

Proxy (com.jcraft.jsch.Proxy)5 ProxyHTTP (com.jcraft.jsch.ProxyHTTP)4 ProxySOCKS5 (com.jcraft.jsch.ProxySOCKS5)4 JSchException (com.jcraft.jsch.JSchException)3 SftpException (com.jcraft.jsch.SftpException)3 IOException (java.io.IOException)3 FileSystemException (org.apache.commons.vfs2.FileSystemException)3 Test (org.junit.Test)1 KettleJobException (org.pentaho.di.core.exception.KettleJobException)1