Search code examples
javaapache-commons-net

commons-net-3.2:mismatch between timestamp and timezone


I am Using FTPClient.java, FTPFile.java,FTPListParseEngine.java from commons-net-3.2.jar to access the files on the ftp server(Linux machine) located in EET timezone. While accessing the files if I try to see the time zone and time stamp of the file,timestamp is shown in UTC format but timezone is shown as timezone of the place where file is being accessed .

Expected was that both should have been in EET format.

Example: Suppose a file sample.txt on FTP server (in EET zone) is created at 11/27/2014 8:28:20 AM. While accessing the file(in EET time zone) using jar mentioned above ,FTPFile.java's getTimestamp method will return time as 11/27/2014 6:28:20 AM EET.

Instead it should have been 11/27/2014 8:28:20 AM EET.

How can this issue be resolved.


Solution

  • Used FTPClientConfig to set timezone as "UTC" and configured FTPClient instance with this. Issue is resolved now.

    FTPClient f=FTPClient();
    
    FTPClientConfig conf = new FTPClientConfig();
    conf.setTimeZoneId("UTC");
    
    f.configure(conf);
    

    http://commons.apache.org/proper/commons-net/javadocs/api-3.3/org/apache/commons/net/ftp/FTPClientConfig.html