Home > database >  Download today's file from FTP server using WinSCP from batch file
Download today's file from FTP server using WinSCP from batch file

Time:01-19

I have a batch file that receives an argument then passes that argument to a text scrip file that invokes WinSCP to download a file.

My goal is to download today's file.

I am able to download the file if in the text script file I don't have >=today.

What do I need to change to download today's file, if it exists?

Batch File

set arg1=%1
set CurrentPath=C:\Temp\

rem drive
c:

rem folder do WinSCP
cd C:\Program Files (x86)\WinSCP

rem Download file
winscp.exe /console /script=%CurrentPath%sftp.txt /parameter %arg1%

Text script file

option batch abort
option confirm off 

# Connect
open <.....> 

# Download file to
get %1%>=today "C:\Temp\"

# Disconnect
close

The error I'm getting:

Mask is invalid near '=today'

enter image description here

CodePudding user response:

I do not think this is about passing parameters.

But the today keyword is a "recent" feature (WinSCP 5.14 from October 2018). So you probably have an old version of WinSCP that does not support it.


If you do not have a version of WinSCP that supports today, you can use %TIMESTAMP% pattern:

get %1%>=%TIMESTAMP#yyyy-mm-dd% "C:\Temp\"

Though you should always use the latest version of WinSCP, if you want to stay safe.

CodePudding user response:

Replace

As-Is

# Download file to
get %1%>=today "C:\Temp\"

To-Be

# Download file to
get -filemask= %1%"*>1D" "C:\Temp\"
  •  Tags:  
  • Related