0

How to get remote file timestamp including milliseconds using jsch framework. I tried as below but till seconds only I get.

ChannelSftp channelSftp = (ChannelSftp) jschSession.openChannel("sftp");
channelSftp.connect();
List<LsEntry> files = channelSftp.ls("*.log");
for (LsEntry entry : files) {
            log.info("File ", entry.getFilename()+":"+entry.getAttrs().getMtimeString());
}

Output:

File app1.log: Fri Dec 23 12:32:52 IST 2022
File app2.log: Fri Dec 23 12:32:52 IST 2022

Expected Output: with timestamp

File app1.log: Fri Dec 23 12:32:52.1234556789 IST 2022
File app2.log: Fri Dec 23 12:32:52.3334556789 IST 2022

Please help to get milliseconds too.

sunleo
  • 10,589
  • 35
  • 116
  • 196

1 Answers1

1

The SFTP protocol can provide milliseconds only since version 4. The JSch supports only SFTP version 3. Even if JSch did support newer version of SFTP, it won't help you probably, as most SFTP servers run on OpenSSH, which supports SFTP 3 only too. So you cannot have really "expected" to get the milliseconds.


If you need milliseconds, you will have to use another library (and mostly likely another server), or completely different API, not SFTP.

If you have a shell access, you can run an appropriate shell command and parse its output. For example:

ls --full-time *.log
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992