I am using the excellent com.jcraft.jsch
API to connect to a remote server using the following code.
JSch ssh = new JSch();
JSch.setConfig(FileTransferConstants.STRICT_HOST_KEY_CHECKING, FileTransferConstants.NO);
session = ssh.getSession(user, host, port);
session.setPassword(password);
session.connect();
channel = session.openChannel(FileTransferConstants.SFTP);
channel.connect();
ChannelSftp sftp = (ChannelSftp) channel;
Once connected, I then use SFTP
to download some log files. This works very well.
Once the files have been retrieved, I interrogate them locally based on the timestamps of the log entries - I am looking for entries within a specific time window.
Up until now it has caused me no problem because my local system timestamp has been very similar to the remote timestamp. But recently my tests started failing due to there now being a 5 minute discrepancy between my local timestamp and that on the remote server.
So my question is, is there is a simple way of getting the remote system time using Jsch
? If so, I would simply retrieve this and use it in my tests instead of my local system time. Then hopefully the discrepancy issue should immediately go away!
Thank you for reading and considering my question.