Using JSch, is there a way to tell if a remote file exists without doing an ls?

Tags: ,



Using JSch, is there a way to tell if a remote file exists without doing an ls and looping through the files to find a name match?

Thanks

Answer

(This is if you’re using the SFTP part of the library, an assumption I made without thinking about it.)

I thought its ls(String path) would accept filenames; I can’t check at the moment.

If it doesn’t, you don’t need to iterate manually; you can use the selector variant:

ls(String path, ChannelSftp.LsEntrySelector selector)


Source: stackoverflow