Search code examples
ftpwinscp

WinSCP script to download files from a list (txt or csv)


I would need help to create a (manual) script to download a bunch of selected files from a designated folder.

All files are in the same folder on the FTP server. The folder holds appr. 80.000 files and I would need to download 1200 of them as set out in a list (e.g. images.txt or images.csv).

I know that it works via get command but don't know which command(s) are needed to call the items in the list, e.g.

001DD1B2-1D73-4C10-A514-BF4EA50A2103.jpg
009F64B8-1458-4238-8B84-D829912D7925.jpg
00B128EF-D6EA-4535-AE36-7AA71AD2E945.jpg
00C30DC0-10FB-4B12-B877-6C6A2E2F9194.jpg

and so on.

The script would be executed manually (no batch needed).


Solution

  • Based on WinSCP article Uploading a list of files, an equivalent batch file for downloading files listed in a .txt file is:

    @echo off
    
    (
      echo open ftp://user:[email protected]/
      echo cd /remote/source/path
      echo lcd C:\local\target\path
    
      rem Generate "get" command for each line in list.txt file
      for /F %%i in (list.txt) do echo get "%%i"
     
      echo exit
    ) > script.tmp
     
    winscp.com /ini=nul /log=script.log /script=script.tmp