Post a reply

Options
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)

Options

Topic review

martin

Re: Combining include and exclude file masks

The mask argument of Session.EnumerateRemoteFiles supports only simple Windows wildcards. Not exclusion masks.
https://winscp.net/eng/docs/library_session_enumerateremotefiles#mask
With the pipe as a mask separator, you have only hit an edge case of internal mask processing implementation. It should have never worked this way. It's actually a bug.

If you do not want to list subdirectories, replace [WinSCP.EnumerationOptions]::AllDirectories with [WinSCP.EnumerationOptions]::None.
pogster123

Combining include and exclude file masks

Hi Martin,

I have a similar situation where I am trying to exclude a subdirectory when calling getfile and putfile. However I am slightly confused by the pipe | that starts the exclusion portion in the filemask.

My PowerShell script is currently working perfectly using pipe as a separator for an INCLUSION filemask designed to get and push certain file types:
$mask = "*.txt|*.ps1|*.bat"
$files = $session.EnumerateRemoteFiles($remotepath, $mask,
    WinSCP.EnumerationOptions]::AllDirectories)

So how can I add a subdirectory EXCLUSION to the existing mask? I have tried
$mask = "*.txt;*.ps1;*.bat|*/", or even just the inclusion file mask with the semicolon separator alone $mask = "*.txt;*.ps1", just to see if the semicolon works.

Files are not getting downloaded with this approach.

Your help would be much appreciated. Thank you for everything you do.
casual

Brilliant, this works, thank you Martin.
casual

Remote sync – filemask to exclude a subfolder

Hello,
I'm trying to use WinSCP (5.1.7 on Windows 7) to set up an automated deployment of a .NET app to an SFTP server (Windows-based shared hosting).
Using the great documentation I was able to get this working except for one part.

I'd like the deployment to ignore a subfolder (e.g. /App_Data/logs/) and all files within.
I've tried to use the exclusion filemask in a dozen different ways but just cannot find the right formula – WinSCP still syncs the subfolder.

This is the command line I use:
winscp /command "option batch abort" "open sftp://login:pwd@server.com/ -hostkey=""ssh-rsa 2048 fingerprint""" "cd /web/content/" "lcd test" "ls" "lls" "synchronize remote -delete -nopermissions -transfer=binary -filemask=""|App_Data/logs/; App_Data/logs/*.*; App_Data/logs/*/*.*""" "close" "exit"

Result (console output) is:
Comparing...

...
Local 'C:\...\test\App_Data\logs' => Remote '/web/content/App_Data/logs'
Synchronizing...
Local 'C:\...\test\App_Data\logs' => Remote '/web/content/App_Data/logs'
'/web/content/App_Data/logs/logs.txt' deleted
C:\...\logs\logs2.txt     |          0 KiB |    0.0 KiB/s | binary |   0%