Question

I am using jSch for SFTP in my Java project. I want to get all files attributes in a directory. But there are two methods to retrieve the file attributes of a file or directory.

1. public SftpATTRS stat(String path)
2. public SftpATTRS lstat(String path)

What is the difference b/w these two methods? Please tell me there uses???

Was it helpful?

Solution

The lstat method gives you the stats of the link itself. Think of it like 'link stat'.

The stat method gives you the stats of the target file itself. (It follows the symbolic link).

Example, you have a symbolic link 'myhome' which is actually a shortcut to /u02/home/alamba.

With stat, you will get attributes of the target of the link, the '/u02/home/alamba' folder. With lstat you will get the attributes of the 'myhome' link instead.

ChannelSftp documentation.

Symbolic Link Explanation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top