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

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
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

Categories

HOME
osgi
gerrit
gremlin
objectgears
programming-languages
yahoo-oauth
google-oauth
electronics
win32gui
ravendb
autotools
webrequest
adfs
amazon-cloudformation
applepay
iggrid
node-pdfkit
volttron
google-cloud-spanner
fortumo
designer
transformation
finite-automata
reactive-cocoa
textfield
introduction
amazonsellercentral
paging
ml
cloudhub
captiveportal
hammerspoon
url-scheme
frame
google-sites-2016
overlap
revolution-slider
hot-module-replacement
ssjs
avro4s
vao
s
babel-core
komodoedit
dds
pnotify
clean-architecture
ionicons
fancybox-2
nodebb
pearson
nbconvert
spring-cache
orthogonal
account-kit
topbeat
deadbolt-2
removechild
autorest
player
yaws
python-3.2
simple-framework
deis
sysinternals
graph-api-explorer
c++03
facebook-graph-api-v2.4
website-monitoring
operator-precedence
clicktag
fpml
android-radiobutton
system.net.webexception
poller
typo3-neos
ivyde
web2py-modules
flash-builder4.5
jquery-mobile-dialog
pygit2
android-hardware
robotics-studio
clipper
kyotocabinet
word-processor
viewswitcher
hosts-file
parametric-equations
wse3.0
qtkit
gnu-prolog
data-loss
invite
winbugs14
telerik-scheduler
lpeg
sproutcore-2
ti-dsp
yagni

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App