afifi
afifi

Reputation: 85

Copy a file with a name criteria using WinSCP scripting

I have a Test folder that contains multiple file with two types of filenames as below:

Cycle2605.zip
Cycle2605_P.zip
Cycle2705.zip
Cycle2705_P.zip

What I manage to do is, move all the file from the folder to other server via WinSCP SFTP as shown in the code below.

open sftp://user:password@hostname/ -hostkey="ecdsa-sha2*******"
put D:\Users\AALADELA\Desktop\Test /cygdrive/d/VB_SHARE/astroQA/AFP/in
exit

But how do I move file that in the filename not contain _P to the destination instead of move all file?

open sftp://user:password@hostname/ -hostkey="ecdsa-sha2*******"
if <filename not contain _p> echo put D:\Users\AALADELA\Desktop\Test /cygdrive/d/VB_SHARE/astroQA/AFP/in
exit

Upvotes: 1

Views: 238

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202168

You can exclude files matching certain pattern with -filemask switch:

put -filemask=|*_P.zip D:\Users\AALADELA\Desktop\Test /cygdrive/d/VB_SHARE/astroQA/AFP/in

Or you can pick only the files you want, if your file name convention allows, e.g.:

put -filemask=Cycle????.zip D:\Users\AALADELA\Desktop\Test /cygdrive/d/VB_SHARE/astroQA/AFP/in

In this case, it's easier to use a Windows wildcard directly in the source path:

put D:\Users\AALADELA\Desktop\Test\Cycle????.zip /cygdrive/d/VB_SHARE/astroQA/AFP/in/

Upvotes: 2

Related Questions