jsch


JSCH setCommand is not working


No Exception comes and Command is also not making any work based on command mentioned.Here permisson of directory is not created and directory is also not created.Please give your suggestion.
Update :
channelexe.getExitStatus is added but problem is it gives -1, what is the meaning of this ?. I don't know how to find some explaination why command is not doing it's job(update 777 mode of fileDir1) .
String depDir = "/usr/local/FTPReceive/DEPLOYED/fileDir1";
log.info("updateDepositedFilePermission ........ starts");
Session session = new FTPComponent().getSession("");
Channel channel = null;
ChannelSftp channelSftp = null;
try
{
session.connect();
System.out.println("session is alive:" + session.isConnected());
channel = session.openChannel("sftp");
channel.connect();
channelSftp = (ChannelSftp) channel;
ChannelExec channelexe = (ChannelExec) session.openChannel("exec");
channelexe.setCommand("chmod 777 -R " + depDir);
channelexe.connect();
System.out.println("channelexe.getExitStatus:"+channelexe.getExitStatus());
}
catch (Exception e1)
{
e1.printStackTrace();
System.out.println("Manual Exception in updateDepositedFilePermission:" + CommonUtil.getExceptionString(e1));
}
channelexe.setCommand("chmod 777 -R " + depDir);
channelexe.setCommand("mkdir /usr/local/fileStore");
channelexe.connect();
A ChannelExec accepts a single command string to invoke on the remote system. Your second call to setCommand() is discarding the chmod command and replacing it with the mkdir command. Assuming the remote shell is bash or similar, you could use shell syntax to construct a command string which runs both commands:
String cmd = "chmod 777 -R " + depDir + " && mkdir /usr/local/fileStore";
channelexe.setCommand(cmd);
No Exception comes...
ChannelExec doesn't throw an exception when a command merely fails. You can call Channel.getExitStatus() to get the exit status of the remote command. The value will be 0 if chmod and mkdir succeeded, or non-zero if they failed. The channel also has functions to read the standard error of the remote command, which will permit you to read any error messages which they output.
The JSCH website has several example programs, including an example of executing a remote command.

Related Links

Decreased speeds when using JSch put compared to scp
JSCH Channel Is Not Opened (New)
What the situation will make channel.getExitStatus() return 1
JSch read local log file
JSCH setCommand is not working
com.jcraft.jsch.JSchException: SSH_MSG_DISCONNECT: 11 No appropriate prime between 1024 and 1024 is available. en
I'm trying to use Jsch to establish an SSH connection in Java.I got the Exception com.jcraft.jsch.jschexception unknownhostkey
com.jcraft.jsch.JSchException: failed to send sftp request
JSch for pbrun not working
JSCH read from input stream hangs from time to time
Hundreds of Apache SSHD clients leave hundreds of OpenSSH daemon processes running
Jsch - ssh connection through ssh tunnel
Changing password using Jsch and ChannelExec
how to delete local file using jsch after file is sent to remote SFTP server directory
com.jcraft.jsch.JSchException: Auth fail error
Creating a new file in SSH enabled system using JSCH

Categories

HOME
pandas
variables
cloud
magnific-popup
azure-data-factory
relayjs
syntax
analysis
jsrender
sharepoint-designer
fsm
ezpublish
convolution
adfs
awesome-wm
volttron
google-cloud-ml
zend-framework3
orchardcms
iron-router
serilog
code-review
viewport
scichart
jtextfield
paging
ml
jquery-ajaxq
tar
facebook-instant-articles
wijmo
social-media
google-cloud-nl
flink-streaming
nouislider
microsoft-chart-controls
react-chartjs
yadcf
airconsole
titanium-mobile
openoffice.org
nssegmentedcontrol
fusionpbx
devextreme
hot-module-replacement
dynamics-crm-2013
streamsets
starteam
jna
lumberjack
gzipstream
grid.mvc
netcdf4
checkboxlist
angular2-meteor
google-datalayer
menuitem
worksheet
python-webbrowser
nstextview
setter
media-player
arrow-keys
synchronous
crosswalk-runtime
quartz-composer
google-cdn
xcb
medium.com
heidisql
trash
skype4py
design-by-contract
thredds
intellij-14
0xdbe
php-ci
event-bubbling
proj4js
notify
inmobi
apache-commons-net
umbraco6
geonetwork
modalpopup
pick
qpainter
java-metro-framework
rdl
marmalade
balanced-payments
pyhdf
bulkloader
padarn
pushbackinputstream
funscript
gdata-api
jspinclude
bigcouch
cufon
coredump
xmemcached
oncheckedchanged
mysql-error-1005
fluent-interface
gamequery
sproutcore-2
database-management
libs
mtj
avatar
wsdl.exe
misv

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