jsch


how to delete local file using jsch after file is sent to remote SFTP server directory


I'm calling jsch in our Mirth interface engine to copy files from our local directory to a remote sftp directory, I want to remove file from local directory after Channel.put has place the file on the remote server directory. Here is my initial code for putting files using javascript code to call jsch in Mirth. Files get to remote directory with no problem.
importPackage(com.jcraft.jsch);
var jsch = new JSch();
jsch.addIdentity("C:\\Directory\\test.key", "test");
jsch.setConfig('StrictHostKeyChecking','no');
var session = jsch.getSession('UserName','datatrans.test.se',22);
session.setTimeout(20000);
//session.setPassword('password');
session.connect();
var channel = session.openChannel('sftp');
channel.connect();
logger.debug('Connected to Biosense SFTP');
var filename = '\\' + $('originalFilename');
logger.debug(filename);
channel.put('D:\\Directory\\*.hl7', filename);
logger.debug('Place files in directory ' + filename);
channel.exit();
logger.debug('exit sftp dir');
session.disconnect();
logger.debug('session completed!');
The ChannelSftp from jsch has an 'rm' command, but it can only be used to remove remote files. You will need to remove the local files with a 'File' object. The File object requires explicit paths... no wildcards allowed, so no one-liners here. Find an example in this question here.

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
openlayers
testng
vbscript
c#-4.0
gremlin
angular-material
hashmap
platform-builder
mean-stack
leon
youtube-api-v3
fsm
callback
disassembler
opengl-es-2.0
directx
google-translate
metatrader4
quickfix
iolanguage
normalizr
crystal-reports-2008
mps
core-text
one-to-many
sparse-matrix
uninstall
xacml
log4js-node
tasklet
fabric8
stormpath
nameservers
grails-3.1
environment-modules
dosbox
automake
occlusion
ssjs
streamreader
graphenedb
http-live-streaming
spring-security-kerberos
total-commander
acoustics
angular2-meteor
user-accounts
flickr-api
youcompleteme
atomicity
jedis
jquery-validate
python-c-api
typescript1.8
capacity
gcsfuse
eventkit
parallel-data-warehouse
android-fonts
log4c
file-writing
multi-level
fody
skobbler-maps
nsfilemanager
paypal-express
react-native-listview
fadeout
ios8-today-widget
collapse
tmuxinator
ios9.1
tween
camanjs
device-manager
preferences
rebol3
xceed-datagrid
algebraic-data-types
intentservice
terminal-services
floating-point-precision
farseer
file-locking
ora-00911
qt-faststart
xamlparseexception
plasma
android-screen-support
jquery-knob
objective-c-2.0
removeclass
bigcouch
file-comparison
visitor-statistic
substrings
libs
procedural-music
port-number
multiple-languages

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