0
votes

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!');
1

1 Answers

0
votes

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.