Preserving date modified when retrieving file using Apache FTPClient

0 votes
I am using org.apache.commons.net.ftp.FTPClient for retrieving files from a ftp server. It is crucial that I preserve the last modified timestamp on the file when its saved on my machine. How to solve this?
Aug 3, 2018 in Selenium by Martin
• 4,220 points
60 views

1 answer to this question.

0 votes

Below will help you:

public boolean retrieveFile(String path, String filename, long lastModified) throws IOException {

    File localFile = new File(path + "/" + filename);

    OutputStream outputStream = new FileOutputStream(localFile);

    boolean success = client.retrieveFile(filename, outputStream);

    outputStream.close();

    localFile.setLastModified(lastModified);

    return success;

}

You can use it like this:

List<FTPFile> ftpFiles = Arrays.asList(client.listFiles());

for(FTPFile file : ftpFiles) {

    retrieveFile("/tmp", file.getName(), file.getTimestamp().getTime());

}
answered Aug 3, 2018 by Samarpit
• 5,130 points

Related Questions In Selenium

0 votes
1 answer

I tried to open a new website when a new tab is opened using Selenium Webdriver

Try this code: ArrayList<String> tabs = new ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,090 points
890 views
0 votes
1 answer

Need to download a file using Selenium

Pretty simple...Find the element or link using ...READ MORE

answered Mar 29, 2018 in Selenium by nsv999
• 5,090 points
407 views
0 votes
1 answer

How do I set the zoom level of Internet Explorer to 100% when using python _winreg

My qustion is, by default for testing ...READ MORE

answered Mar 30, 2018 in Selenium by nsv999
• 5,090 points
791 views
0 votes
1 answer

Maven pom.xml file issue USING SELEINUM WebDriver using Firfox

You don't need to change anything in ...READ MORE

answered Apr 3, 2018 in Selenium by ned_crew
• 1,620 points
58 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,090 points
555 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
889 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
552 views
0 votes
1 answer
0 votes
1 answer

Returning null element when using following and preceding XPath selector

To identify the <input> tag with respect to the <label> tag ...READ MORE

answered Jun 8, 2018 in Selenium by Samarpit
• 5,130 points
97 views