get latest file from ftp

后端 未结 2 668
逝去的感伤
逝去的感伤 2021-01-17 18:54

Trying to create a simple plugin that simply connects to an ftp site, looks up the latest file and then downloads it. However, it isn\'t getting the latest file.

I\'

2条回答
  •  遇见更好的自我
    2021-01-17 19:05

    I see only one mistake:

    FTPFile choice = null;
    

    If the first file were the latest modified file, then the method would return null, causing a potential NullPointerException.

    Change it to

    FTPFile choice = files[0];
    

    and the logic should be right.

    If it still doesn't return the expected file, then most likely the file in question simply doesn't have the expected last modified date. Add something like this to the for loop in the method:

    System.out.println(file.getTimestamp().getTime() + " - " + file.getName());
    

    And look closer.

提交回复
热议问题