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

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

Categories

HOME
java
client
homebrew
view
relayjs
q
infragistics
jxls
binary-tree
umd
callback
disassembler
blueprintjs
networkx
amazon-cloudformation
slick-slider
row
serverless-framework
progressive-web-apps
reactive-cocoa
object-detection
riot.js
lcd
filezilla
rst2pdf
spring-mybatis
minitab
publish
compatibility
newline
gsmcomm
media-queries
binary-data
ioio
siesta-swift
scorm2004
jspresso
grails-3.1
uiswipegesturerecognizer
rotational-matrices
bytecode-manipulation
file-format
disassembling
libraries
android-browser
unspecified
trim
particles.js
avro4s
ibpy
android-mediaprojection
vao
thin
prolog-setof
python-webbrowser
idisposable
worker-thread
sqlbulkcopy
iso8601
dynamics-sl
query-performance
topbeat
root-framework
trash
autorest
markojs
ready-api
yaws
bluegiga
rhino-servicebus
maven-tomcat-plugin
wso2cloud
lib.web.mvc
t4mvc
collapse
sysinternals
graph-drawing
fluid-dynamics
notify
ng-animate
coldbox
angularjs-ng-click
winddk
javafx-webengine
xcode-6.2
flask-cors
castle
google-reader
reactfx
hyprlinkr
transcoding
openlaszlo
fmod
page-layout
farseer
excel-2003
jplaton
yui-compressor
comaddin
enterprisedb
smtp-auth
venn-diagram
propertyeditor
armcc
javaspaces
errai
online-compilation
netdna-api
mod-auth
joyent
psi
asp.net-mvc-areas
dmx512
webkit.net
kdbg
javap
backcolor
swing-app-framework
project-hosting
port-number
genealogy
ubuntu-9.04

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