use of com.jcraft.jsch.ProxyHTTP 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);
}
use of com.jcraft.jsch.ProxyHTTP 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);
}
use of com.jcraft.jsch.ProxyHTTP in project incubator-gobblin by apache.
the class SftpFsHelper method connect.
/**
* Opens up a connection to specified host using the username. Connects to the source using a private key without
* prompting for a password. This method does not support connecting to a source using a password, only by private
* key
* @throws org.apache.gobblin.source.extractor.filebased.FileBasedHelperException
*/
@Override
public void connect() throws FileBasedHelperException {
String privateKey = PasswordManager.getInstance(this.state).readPassword(this.state.getProp(ConfigurationKeys.SOURCE_CONN_PRIVATE_KEY));
String password = PasswordManager.getInstance(this.state).readPassword(this.state.getProp(ConfigurationKeys.SOURCE_CONN_PASSWORD));
String knownHosts = this.state.getProp(ConfigurationKeys.SOURCE_CONN_KNOWN_HOSTS);
String userName = this.state.getProp(ConfigurationKeys.SOURCE_CONN_USERNAME);
String hostName = this.state.getProp(ConfigurationKeys.SOURCE_CONN_HOST_NAME);
int port = this.state.getPropAsInt(ConfigurationKeys.SOURCE_CONN_PORT, ConfigurationKeys.SOURCE_CONN_DEFAULT_PORT);
String proxyHost = this.state.getProp(ConfigurationKeys.SOURCE_CONN_USE_PROXY_URL);
int proxyPort = this.state.getPropAsInt(ConfigurationKeys.SOURCE_CONN_USE_PROXY_PORT, -1);
JSch.setLogger(new JSchLogger());
JSch jsch = new JSch();
log.info("Attempting to connect to source via SFTP with" + " privateKey: " + privateKey + " knownHosts: " + knownHosts + " userName: " + userName + " hostName: " + hostName + " port: " + port + " proxyHost: " + proxyHost + " proxyPort: " + proxyPort);
try {
if (!Strings.isNullOrEmpty(privateKey)) {
List<IdentityStrategy> identityStrategies = ImmutableList.of(new LocalFileIdentityStrategy(), new DistributedCacheIdentityStrategy(), new HDFSIdentityStrategy());
for (IdentityStrategy identityStrategy : identityStrategies) {
if (identityStrategy.setIdentity(privateKey, jsch)) {
break;
}
}
}
this.session = jsch.getSession(userName, hostName, port);
this.session.setConfig("PreferredAuthentications", "publickey,password");
if (Strings.isNullOrEmpty(knownHosts)) {
log.info("Known hosts path is not set, StrictHostKeyChecking will be turned off");
this.session.setConfig("StrictHostKeyChecking", "no");
} else {
jsch.setKnownHosts(knownHosts);
}
if (!Strings.isNullOrEmpty(password)) {
this.session.setPassword(password);
}
if (proxyHost != null && proxyPort >= 0) {
this.session.setProxy(new ProxyHTTP(proxyHost, proxyPort));
}
UserInfo ui = new MyUserInfo();
this.session.setUserInfo(ui);
this.session.setDaemonThread(true);
this.session.connect();
log.info("Finished connecting to source");
} catch (JSchException e) {
if (this.session != null) {
this.session.disconnect();
}
log.error(e.getMessage(), e);
throw new FileBasedHelperException("Cannot connect to SFTP source", e);
}
}
Aggregations