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
Actually in my project ls working without loops. I just pass to the ls call path with filename.
private static boolean exists(ChannelSftp channelSftp, String path) {
Vector res = null;
try {
res = channelSftp.ls(path);
} catch (SftpException e) {
if (e.id == SSH_FX_NO_SUCH_FILE) {
return false;
}
log.error("Unexpected exception during ls files on sftp: [{}:{}]", e.id, e.getMessage());
}
return res != null && !res.isEmpty();
}
For example there a file file.txt with an url sftp://user@www.server.comm/path/to/some/random/folder/file.txt. I pass to function exists path as /path/to/some/random/folder/file.txt