This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Java in General and the fly likes List Files of Remote Directory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "List Files of Remote Directory" Watch "List Files of Remote Directory" New topic

List Files of Remote Directory

Vivek Sam

Joined: Jul 29, 2004
Posts: 8
Hi ,

I have a requirement to dynamically select a file from a remote location based on the regular expression.

Now i used to list the files , this fails as it says that the parameter directory is not a directory.

Now i understand that the it is looking on the local system for the directory , Can anybody tell me as to how can I connect to the remote machine and list the files at that location

If it is a complex task , can anybody please suggest a simple way to search for a file present on the remote location using regex.

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46437
Certainly too difficult for us on "beginning". Maybe the "in General" people will be able to cope
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

We don't know anything about the network which includes your computer and this remote directory, so we can only guess.

Okay. My guess is that maybe you can map a drive to this remote directory before you run the code.
H Paul
Ranch Hand

Joined: Jul 26, 2011
Posts: 471
I take this as an opportunity to learn new way of doing this.

Without any technical environment/constraint, here is my guess:

My guess: May or not work

Use FTPClient

FTPFile[] listFiles(String pathname, FTPFileFilter filter)
Version of listFiles(String) which allows a filter to be provided.

And implement FTPFileFilter
Vivek Sam

Joined: Jul 29, 2004
Posts: 8
Hi All,

Resolved the issue by using JSch , basically a SFTP connection to the Remote machine.

Please refer the below links for example and the home page of the same.

JSch Home Page

JSch SFTP Example

Thanks to all for their replies.
I agree. Here's the link:
subject: List Files of Remote Directory
It's not a secret anymore!