I want to identify whether a the given path is a valid path for file or directory using net.schmizz.sshj.sftp.SFTPClient api and based on i need to take decision that if it is a valid file path then i need to access its parent directory. my code looks like below> SSHClient ssh = new SSHClient(); String rsaKey = "e3:27:12:a9:62:9a:46:cc:98:ee:0d:b7:38:72:a0:63"; String host = "10.235.1.154"; String uName = "root"; String pwd = "pspl@123"; String url = "/root/ram2.log/"; String testUrl = host + url; ssh.addHostKeyVerifier(rsaKey); List fileItems = new ArrayList();
1.try {
2. ssh.connect(host);
3. ssh.authPassword(uName,pwd);
4. SFTPClient sftp = ssh.newSFTPClient();
5.
6. if(testUrl.startsWith(host)){
7. String[] splitedStrings = testUrl.split(host);
8. String str = splitedStrings[1];
9. url = str;
10. }else{
11. url = url;
12. }
13.
14.
15. List<RemoteResourceInfo> fileInfoList = sftp.ls(url, new RemoteResourceFilter() {
16. public boolean accept(RemoteResourceInfo rrInfo) {
17. return rrInfo.getName().charAt(0) != '.';
18. }
19. });
20.
21.
22. for (RemoteResourceInfo fileInfo : fileInfoList) {
23. //files.add(str + "/" + fileInfo.getName());
24. String fileName = fileInfo.getName();
25. if (fileInfo.isDirectory()) {
FileItem childFileItem = new FileItem();
childFileItem.setPath(host + url + fileName);
fileItems.add(childFileItem);
} else {
int dotIndex = fileName.lastIndexOf('.');
String ext = dotIndex > 0 ? fileName
.substring(dotIndex + 1) : "";
FileItem childFileItem = new FileItem();
childFileItem.setPath(host + url + fileName);
childFileItem.setDirectory(false);
fileItems.add(childFileItem);
}
}
} catch (IOException e) {
System.out.println("Couldn't resolve host : {} "+ host);
}
return fileItems;
Problem: Line no. 15 is throwing error saying no such file if I m giving the path as "/root/ram2.log/" even though the file ram2.log does exis on server.
Any help on this wud be graet helpful.