This discussion is archived
8 Replies Latest reply: Nov 12, 2009 12:06 PM by DrClap RSS

org.apache.commons.net.ftp.FTPFile how to get files timestamp

807580 Newbie
Currently Being Moderated
Hi, I've got a problem while accesing file's date in a remote server. The thing is, my pc hour is 6 hours less than the server's one, but if I try to get a recently created file's date it gives me this:

Wed Nov 11 00:00:00 GMT-03:00 2009

I guess this is because the file's timestamp is greater than my pc's time, but I don't know how to solve it. Anyway, if you can help me I would be very thankfull.

PS: sorry for my bad english..
  • 1. Re: org.apache.commons.net.ftp.FTPFile how to get files timestamp
    jschellSomeoneStoleMyAlias Expert
    Currently Being Moderated
    You get that every time you request a timestamp regardless of when the file was created? If so then you are out of luck.

    If it varies then see the java.txt.SimpleDateFormat class
  • 2. Re: org.apache.commons.net.ftp.FTPFile how to get files timestamp
    807580 Newbie
    Currently Being Moderated
    No, only if the file's timestamp is greater than my pc's time.
  • 3. Re: org.apache.commons.net.ftp.FTPFile how to get files timestamp
    jschellSomeoneStoleMyAlias Expert
    Currently Being Moderated
    As noted then, look at java.txt.SimpleDateFormat to parse it.
  • 4. Re: org.apache.commons.net.ftp.FTPFile how to get files timestamp
    807580 Newbie
    Currently Being Moderated
    But I don't want to parse it, I misexplained myself (I probably invented that word). The problem is that the file's timestamp shouldn't be 00:00:00, it isn't showing the real date because it is greater than my pc's I think. (the problem is with the hour, minutes and seconds)

    Thanks for replying.
  • 5. Re: org.apache.commons.net.ftp.FTPFile how to get files timestamp
    jschellSomeoneStoleMyAlias Expert
    Currently Being Moderated
    Lautaz wrote:
    But I don't want to parse it, I misexplained myself (I probably invented that word). The problem is that the file's timestamp shouldn't be 00:00:00, it isn't showing the real date because it is greater than my pc's I think. (the problem is with the hour, minutes and seconds)
    That would be the part where I asked you if your were getting the same value every time. So regardless of when the file is created you are getting 00:00:00.

    So the next question is - how are you getting that value? What is the exact process that you use?

    And have you tried using an FTP gui client to see what the server is returning to you (outside of java)? If the server doesn't give you the time then nothing you do in java will fix that.
  • 6. Re: org.apache.commons.net.ftp.FTPFile how to get files timestamp
    DrClap Expert
    Currently Being Moderated
    Lautaz wrote:
    No, only if the file's timestamp is greater than my pc's time.
    That seems unlikely to me. But it's open-source. You could always get the source code and see whether it's really doing that. And if it is, just remove that little if-statement and recompile it.
  • 7. Re: org.apache.commons.net.ftp.FTPFile how to get files timestamp
    807580 Newbie
    Currently Being Moderated
    Here's my code:
    FTPFile[] files = ftp.listFiles();
    
    for (int i = 0; i < files.length; i++) {
       Date fileDate = files.getTimestamp().getTime();
    System.out.println(fileDate);
    }
    For example if I have a file that was created at 6 PM (in another server with another timezone) and my pc time is 4 PM it won't work, it will print the right date but the hour, minutes and seconds will all be 00.
    Now if I have a file created at 3 PM on that same server, everything works fine.
    
    Edited by: Lautaz on Nov 13, 2009 11:41 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
  • 8. Re: org.apache.commons.net.ftp.FTPFile how to get files timestamp
    jschellSomeoneStoleMyAlias Expert
    Currently Being Moderated
    Lautaz wrote:
    For example if I have a file that was created at 6 PM (in another server with another timezone) and my pc time is 4 PM it won't work, it will print the right date but the hour, minutes and seconds will all be 00.
    Now if I have a file created at 3 PM on that same server, everything works fine.
    Either you get the time or you don't. If you get it sometimes and not others then that means that either you are misunderstanding something or something odd is going on with the server.

    As I suggested you need to use a ftp client gui tool to confirm what the server is doing. The behavior of FTP servers is not consistent across different servers.