Topic "Power shell script wincsp synchronizedirectories file mask not working"

Author Message
[View user's profile]

Joined: 2015-10-09
Posts: 1
Location: Ellesmere Port, Cheshire
this is my first post to the forum so I hope someone can help.

I have a PowerShell script with the following code

$sessionOptions = New-Object WinSCP.SessionOptions
$sessionOptions.Protocol = [WinSCP.Protocol]::ftp
$sessionOptions.HostName = $Remote_Host
$sessionOptions.UserName = $UserName
$sessionOptions.Password = $Password
$session = New-Object WinSCP.Session
$transferoptions= New-Object WinSCP.TransferOptions
$transferOptions.FileMask = "*.TXT | RESULT*"

# Synchronize files to local directory, collect results
$synchronizationResult = $session.SynchronizeDirectories([WinSCP.SynchronizationMode]::local, $localPath, $remotePath, $False, $TransferOptions)

It works fine except the file mask does not exclude the RESULT* files in the directory. Am I doing something wrong?

WinSCP version is WinSCP 5.7.5
Windows version is server 2012

Many thanks for any help
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24736
Location: Prague, Czechia
Please attach a full session log file showing the problem (using the latest version of WinSCP).

To generate log file, set Session.SessionLogPath. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.


Many thanks for your reply but I managed to resolve the issue using

$transferOptions.FileMask = "|RESULT*"
$transferResult = $session.GetFiles($remotePath, $localPath, $False, $transferOptions)

instead, as that seems to work with the file mask where as

$transferOptions.FileMask = "|RESULT*"
$synchronizationResult = $session.SynchronizeDirectories([WinSCP.SynchronizationMode]::local, $localPath, $remotePath, $False , $transferOptions)

does not.
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24736
Location: Prague, Czechia
I can also see your problem now.
The TransferOptions is 7th argument of SynchronizeDirectories. While you pass it as 5th argument.

You can post new topics in this forum

Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!


About donations

$9   $19   $49   $99

About donations


WinSCP Privacy Policy

WinSCP License