V
V
vitya_brodov2021-09-16 07:13:48
Java
vitya_brodov, 2021-09-16 07:13:48

How to download selected file from FTP server?

Task: Select the latest file from the FTP server and download.

I have implemented:
Select the latest file from the FTP server (but I can not download)
Question: how to download a file without specifying the path?
the code:

try {
            client.connect(server);
            client.login(username, password);
            FTPFile[] files = client.listFiles();
           // как скачать этот файл?
            FTPFile lastFile = lastFileModified(files);
            client.disconnect();

        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    public static FTPFile lastFileModified(FTPFile[] files) {
        Date lastMod = files[0].getTimestamp().getTime();
        FTPFile choice = files[0];
        for (FTPFile file : files) {
            if (file.getTimestamp().getTime().after(lastMod)) {
                choice = file;
                lastMod = file.getTimestamp().getTime();
                System.out.println("TIME: " + file.getTimestamp().getTime() + "\n FILE NAME:  " + file.getName());

            }
        }
        return choice;
    }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question