LewisMCT333
LewisMCT333

Reputation: 105

Batch file - Download the latest FTP folder

I'm trying to download the latest folder from an FTP server. This folder contains several folders in which contains several CSV files.

The issue I have is that the folders are created each day and each time I run the script I only want it to download the latest folder at that location.

I have not the foggiest idea of how to specify this, or even download an entire folder structure from an FTP using batch file.

Please let me know if any additional information is required and I will provide it immediately, thanks again for your help.

Kind Regards,
Lewis

Upvotes: 2

Views: 1591

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202168

There's no easy way to select the most recent folder with the built-in Windows FTP client, the ftp.exe. You would have more luck with a PowerShell script and the FtpWebRequest.

But even if you manage to select the most recent directory, neither the ftp.exe nor the FtpWebRequest support recursive downloads anyway.

You better use some more powerful 3rd party FTP client.


For example with WinSCP FTP client you can download the latest file or folder, using the -latest switch of the get command (WinSCP 5.9 and newer):

winscp.com /command ^
    "open ftp://username:[email protected]/" ^
    "cd /remote/path" ^
    "lcd c:\local\path" ^
    "get -latest *" ^
    "exit"

See also the guide to downloading the most recent file with WinSCP.

(I'm the author of WinSCP)

Upvotes: 1

Related Questions