I want to have files with names File1.txt filE2.txt FIle3.txt
I want to list down all three files when I pass the fileMask as a file. basically, I want to do a case insensitive search using the channel.ls(path + fileMask , selector)
I want to have files with names File1.txt filE2.txt FIle3.txt
I want to list down all three files when I pass the fileMask as a file. basically, I want to do a case insensitive search using the channel.ls(path + fileMask , selector)
To search for a particular file in the sftp location , just do something like :
remoteFileName = "fileName_[0-9]{08}.txt"
try {
ChannelSftp channelSftp = setupJsch();
channelSftp.connect();
Vector ls = channelSftp.ls(remoteFilePath);
Pattern pattern = Pattern.compile(remoteFileName, Pattern.CASE_INSENSITIVE);
for (Object entry : ls) {
ChannelSftp.LsEntry e = (ChannelSftp.LsEntry) entry;
Matcher m = pattern.matcher(e.getFilename());
if (m.matches()) {
//Do something
channelSftp.get(remoteFilePath + e.getFilename(), getLocalFileDir());
channelSftp.exit(); //If you want to search for multiple files then do not terminate the connection here
}
}
} catch (JSchException jSchException) {
LOGGER.info("File download failed :", jSchException);
} catch (SftpException sftpException) {
LOGGER.info("File download failed :", sftpException);
}