throw new FileSystemException("vfs.provider.sftp/load-private-key.error", privateKeyFile, e);
}
}
}
Session session;
try
{
session = jsch.getSession(new String(username),
hostname,
port);
if (password != null)
{
session.setPassword(new String(password));
}
Integer timeout = SftpFileSystemConfigBuilder.getInstance().getTimeout(fileSystemOptions);
if (timeout != null)
{
session.setTimeout(timeout.intValue());
}
UserInfo userInfo = SftpFileSystemConfigBuilder.getInstance().getUserInfo(fileSystemOptions);
if (userInfo != null)
{
session.setUserInfo(userInfo);
}
Properties config = new Properties();
//set StrictHostKeyChecking property
String strictHostKeyChecking =
SftpFileSystemConfigBuilder.getInstance().getStrictHostKeyChecking(fileSystemOptions);
if (strictHostKeyChecking != null)
{
config.setProperty("StrictHostKeyChecking", strictHostKeyChecking);
}
//set PreferredAuthentications property
String preferredAuthentications = SftpFileSystemConfigBuilder.getInstance().
getPreferredAuthentications(fileSystemOptions);
if (preferredAuthentications != null)
{
config.setProperty("PreferredAuthentications", preferredAuthentications);
}
//set compression property
String compression = SftpFileSystemConfigBuilder.getInstance().getCompression(fileSystemOptions);
if (compression != null)
{
config.setProperty("compression.s2c", compression);
config.setProperty("compression.c2s", compression);
}
String proxyHost = SftpFileSystemConfigBuilder.getInstance().getProxyHost(fileSystemOptions);
if (proxyHost != null)
{
int proxyPort = SftpFileSystemConfigBuilder.getInstance().getProxyPort(fileSystemOptions);
SftpFileSystemConfigBuilder.ProxyType proxyType =
SftpFileSystemConfigBuilder.getInstance().getProxyType(fileSystemOptions);
Proxy proxy = null;
if (SftpFileSystemConfigBuilder.PROXY_HTTP.equals(proxyType))
{
if (proxyPort != 0)
{
proxy = new ProxyHTTP(proxyHost, proxyPort);
}
else
{
proxy = new ProxyHTTP(proxyHost);
}
}
else if (SftpFileSystemConfigBuilder.PROXY_SOCKS5.equals(proxyType))
{
if (proxyPort != 0)
{
proxy = new ProxySOCKS5(proxyHost, proxyPort);
}
else
{
proxy = new ProxySOCKS5(proxyHost);
}
}
if (proxy != null)
{
session.setProxy(proxy);
}
}
//set properties for the session
if (config.size() > 0)
{
session.setConfig(config);
}
session.setDaemonThread(true);
session.connect();
}
catch (final Exception exc)
{
throw new FileSystemException("vfs.provider.sftp/connect.error", new Object[]{hostname}, exc);
}