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,320 points
1,090 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,910 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,500 points
3,989 views
0 votes
1 answer

Need to download a file using Selenium

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

answered Mar 30, 2018 in Selenium by nsv999
• 5,500 points
3,204 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,500 points
3,090 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,610 points
1,360 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,500 points
12,730 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

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

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
8,616 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,910 points
6,692 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 3, 2020 in Selenium by Sri
• 3,190 points
7,555 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,910 points
2,936 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP