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,330 points
299 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,890 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,510 points
1,936 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,510 points
1,382 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,510 points
1,532 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
260 views
0 votes
2 answers

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,510 points
3,477 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31 in Selenium by Sri
• 2,970 points
4,488 views
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,890 points
2,569 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 2 in Selenium by Sri
• 2,970 points
2,807 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,890 points
786 views