jsch


JSCH Channel Is Not Opened (New)


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)
The output on mistake was non-informative (as well as scarse documentation on the library). The reason was in managing server rsa-keys on connection. I wanted no ui dialogs and full automation (UserInfo disabled).
Also StrickedHostKeyChecking should be no, although it's unsafe. Setting it to "no" allows autoadding rsa-keys to local keys repository (e.g. ~/.ssh/known_hosts).
Finally resulted in a 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 to system file like known_hosts by
// 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 to known_hosts
Unknown hostkey management

Related Links

Creating a new file in SSH enabled system using JSCH
How to interact with the script after its execution using Jsch
java jsch -executing multiple unix commands
How to get one stream from error stream and input stream when calling a script using JSCH
SFTP using jschexception verify false sometimes fails
how to increase the jsch buffer size?
The cipher 'aes256-cbc' is required, but it is not available
How to pause/resume procedure while/after upload file by ChannelSftp
jsch + running multiple command in shell after SU and then close channal
NGit/Nsch Generating SSH Keypair (c# Jgit)
Extract userInfo from JSCH stream
Running a Shell Script using java ( process Builder ) with a specific unix user
Java jsch and resuming file upload after interruption?
How to pass a variable through channel in Jsch?
How to handle passwords prompts in expectj
Retaining the last modified date while using ChannelSftp for file transfer

Categories

HOME
coq
path-finding
youtube-dl
sqlite-net-extensions
sharepoint-designer
ravendb
acquia
gnupg
midi
rascal
modx-revolution
nstableview
quartz-scheduler
ef-migrations
shared-hosting
visjs
kudan
telerik-reporting
autosys
dxf
su
apache-commons-io
brunch
bootstrap-material-design
fgetcsv
large-file-upload
subdomains
procdump
webtest
uiswipegesturerecognizer
picasso
swisscomdev
dism
arena-simulation
flashair
qcombobox
angular2-meteor
auto-update
scrollable
pango
theming
rdfs
feeds
mcafee
minimization
nested-sets
ableton-live
android-fonts
vmware-tools
home-directory
prettytensor
skype4py
ready-api
livequery
kendonumerictextbox
wso2cloud
icu4j
remobjects
pretty-print
notify
directoryservices
qpainter
internet-connection
has-many-through
p4java
back-stack
yui-compressor
type-equivalence
gil
javaspaces
twrequest
appconkit
assembly-loading
bigcouch
fireworks
xdomainrequest
dmx512
filtered-index
perfect-hash
firefox-5
nintendo-ds
zune

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App