1

I have the following script in WinSCP (version 5.9.5 (Build 7441)) running on a windows machine

# Establish the connection that was saved as MySFTPsite using GUI 
open MySFTPsite
synchronize remote -filemask="*.CSV" "K:\extract\" "/sftp_uploads/"

I call this via a batch file.

This works fine, except it sends ALL the .CSV files in the extract folder.

There is another process that writes a file ever hour into the extract folder.

I want to send only the LATEST .CSV file in this extract folder. How can I do this please?

The remote server that I upload to deletes the file once it processes the file.. so synchronize will always send all the files over and over again.

I'm not sure how to format the filemask in the script or use multiple filemasks (if there is such a thing or even possible).

I do not want to use PowerShell.

I want to keep this as simple as possible and use the script that I have.

Any help would be appreciated.

2 Answers 2

1

Use -latest switch of put command:

put -latest "K:\extract\*.csv" "/sftp_uploads/"

While -filemask="*.CSV>2H may do for you, if the files are added infrequently, it's not the right solution in general.

For discussion about all possibilities, see WinSCP article on Uploading the most recent file.

1

It's ok.. I have figured out the answer

here it is

-filemask="*.CSV>2H 

This filters files modified in the last 2 hours. Should have looked a little closer at the following:

https://winscp.net/eng/docs/file_mask

I'll leave this here for anyone who might be looking - but not looking hard enough!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.