0

I need to transfer list of files from different directories to the destination. I am using JSch library for this purpose.

I can get the list of files or directory list with below mentioned code for the Remote machine.

var jsch = new JSch();
jsch.setConfig('StrictHostKeyChecking','no');
var session = jsch.getSession('username','hostaddress',portnumber);
session.setPassword('password');
session.connect();
var channel = session.openChannel('sftp');
channel.connect();
channel.cd("/direcotry/");
var directoryList = channel.ls("*.txt");

But is there any command/code to get the list of directories and files from the local machine (Linux OS) using jcraft? Because number of directories and files differ during each transfer from the source.

FYI. I need to implement this solution in mirth connect.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Sachin
  • 13
  • 3
  • 2
    I can't make sense of the language here. This is not JavaScript as JCraft is a Java library but the code isn't Java. Is this Groovy? – Tunaki Oct 25 '15 at 13:38

2 Answers2

0

You use JSch to access remote files, not local files.


For local files, use functions for listing local files available in your language/SDK.

For Java see, Read all files in a folder.

Community
  • 1
  • 1
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • Well, this helps me to get local file/directory but I can't transfer a file at remote machine nor send it to jsch code to transfer that file at remote machine. – Sachin Oct 25 '15 at 15:42
  • Your question was "how to list local files". Not how to upload them. I've answered your question. To upload a file, use [`ChannelSftp.put`](http://epaul.github.io/jsch-documentation/simple.javadoc/com/jcraft/jsch/ChannelSftp.html#put%28java.lang.String,%20java.lang.String%29) – Martin Prikryl Oct 25 '15 at 17:02
  • Thanks for your answer. – Sachin Nov 04 '15 at 19:16
0

org.apache.commons.io.FileUtils has a listFilesAndDirs method

https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/FileUtils.html