PROBLEM: Connecting remote site by SFTP using JSCH library results in "Channel is not opened". Code works fine from one internet connection, but fails from another. Another is done via proxy. Nevertheless, I can connect by SFTP from another, using FileZilla client.
RESEARCH: Tried increasing connection timout and setting useDNS: false from similar questions. I've got session and channel opned from it. Still, after timout, channel connection fails.
QUESTION: How to get connection.
Below is the code and error stack trace extracts:
JSch jsch = new JSch();
UserInfo userInfo ;
jsch.setKnownHosts(KNOWN_HOSTS);
session = jsch.getSession(
Menue.SITE_LOGIN,
Menue.SITE_HOST,
Menue.SITE_PORT);
session.setPassword(
Menue.SITE_PASSWORD);
if (Menue.USE_PROXY) {
session.setProxy(
new ProxyHTTP(
Menue.PROXY_HOST,
Menue.PROXY_PORT));
}
session.setConfig(
"StrictHostKeyChecking",
"yes");
session.connect();
channel = session.openChannel("sftp");
channel.setInputStream(System.in);
channel.setOutputStream(System.out);
channel.connect(60 * 1000); // Error: channel is not opened.
Stacktrace:
com.jcraft.jsch.JSchException: channel is not opened. at com.jcraft.jsch.Channel.sendChannelOpen(Channel.java:765) at com.jcraft.jsch.Channel.connect(Channel.java:151)