Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference b/w ChannelSftp's lstat() and stat() method in jSch

Tags:

java

ssh

sftp

jsch

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???

like image 927
earthmover Avatar asked Jan 20 '14 06:01

earthmover


People also ask

What is ChannelSftp?

public class ChannelSftp extends Channel. A Channel connected to an sftp server (as a subsystem of the ssh server). This class supports the client side of the sftp protocol, version 3, and implements an interface similar to the usual sftp command line client.

What is Lsentry in Java?

Represents a directory entry, representing a remote file or directory. A vector of objects of this inner class is returned by ChannelSftp.ls(java. lang.

What is JSch session?

JSch is a pure Java implementation of SSH2. JSch allows you to connect to an sshd server and use port forwarding, X11 forwarding, file transfer, etc., and you can integrate its functionality into your own Java programs. JSch is licensed under BSD style license.


1 Answers

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.

like image 69
Damienknight Avatar answered Sep 29 '22 15:09

Damienknight