Kush Sahu Kush Sahu - 1 year ago 144
Java Question

How to get only directories and text files using SFTP channel of JSch?

Hi I am developing an application which connects to remote server and browses through different directories.

Here I want to show only directories and text files to user. Using SFTP channel in JSch, I can execute

method. But this method can give me result for either in this format
. Using
separately I can get directories list and text file list. Since I am using it separately I have to use 2 different
methods like:


1st gives me all entries from which I have to loop and filter directories. In second, I get all text files.

How can I get directories list and text file list using minimum code. I don't want to loop twice. Thanks

Answer Source

Use ls(""). Then loop the returned entries, and select only those you want.

I.e. those that have LsEntry.getFilename() ending with ".txt" or LsEntry.getAttrs().isDir().

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download