Post a reply

Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)


Topic review


Re: How to download to new folder

WinSCP script cannot create local folders. You have to create the folder in the batch file, before you start WinSCP. But you can use WinSCP %TIMESTAMP% syntax to generate the folder name.
See Formatting Timestamp in Batch File.
So something like this:
set TIMESTAMP_FORMAT=yyyy-mm-dd
for /F "tokens=* USEBACKQ" %%F in (
    ` /command "echo %%TIMESTAMP#%TIMESTAMP_FORMAT%%%" "exit"`
) do set TIMESTAMP=%%F
"C:\Program Files (x86)\WinSCP\" ^
  /command ^
    "lcd ""%TARGET_PATH%""" ^

How to download to new folder with today date


I'm new to WinSCP and to scripting so please forgive my lack of knowledge.

I have created a .bat file to automatically download several files from an FTP server. I have added this .bat file to Windows Task Scheduler so it will run several times each day.

Now I would like to know how to add a function to my .bat file that creates a new folder with the current date and time, then downloads the files into the newly created folder.

My .bat file currently looks like this:
"C:\Program Files (x86)\WinSCP\" ^ 
  /log="C:\Users\xxxxxx\WinSCP.log" /ini=nul ^
  /command ^
    "open" ^
    "cd /xxx/xxx/xxx/xxx" ^
    "lcd ""C:\Users\Data""" ^
    "get" ^
    "get" ^
    "get" ^
if %WINSCP_RESULT% equ 0 (
  echo Success
) else (
  echo Error

Is there a way to have this same script create a new folder with today date and time in C:\Users\Data and then download the files there?

Many thanks