JSCH Channel Is Not Opened (New) -


problem: connecting remote site sftp using jsch library results in "channel not opened". code works fine 1 internet connection, fails another. done via proxy. nevertheless, can connect sftp another, using filezilla client.

research: tried increasing connection timout , setting usedns: false similar questions. i've got session , channel opned it. still, after timout, channel connection fails.

question: how connection.

below code , 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 not opened. 

stacktrace:

com.jcraft.jsch.jschexception: channel not opened. @ com.jcraft.jsch.channel.sendchannelopen(channel.java:765) @ com.jcraft.jsch.channel.connect(channel.java:151)

the output on mistake non-informative (as scarce documentation on library). reason in managing server rsa-keys on connection. wanted no ui dialogs , full automation (userinfo disabled).

also strickedhostkeychecking should no, although it's unsafe. setting "no" allows autoadding rsa-keys local keys repository (e.g. ~/.ssh/known_hosts).

finally resulted in code:

try {   jsch jsch = new jsch();    jsch.setknownhosts("~/.ssh/known_hosts");    session session = jsch.getsession(     "my_login",     "my.host",     22);    session.setpassword(     "password");    // autoadd system rsa-keys system file known_hosts   // disabling strick keys checking:   java.util.properties config = new java.util.properties();   config.put(     "stricthostkeychecking",     "no");   session.setconfig(config);    session.connect();    channel channel = session.openchannel("sftp");   channel.connect();   channelsftp sftpchannel = (channelsftp) channel;    system.out.println(         sftpchannel.ls("/"));    session.disconnect(); } catch (exception e) {   system.out.println(e); } 

these articles helped:

original example on knownhosts

adding rsa known_hosts

unknown hostkey management


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -