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

Author Message
wyssp4
[View user's profile]

Joined: 2015-10-09
Posts: 1
Location: Ellesmere Port, Cheshire
Hi,
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.SessionLogPath
$session = New-Object WinSCP.Session
$session.Open($sessionOptions)
$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
Steve
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
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.
Steve.Spreyer

Guest


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.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
I can also see your problem now.
The TransferOptions is 7th argument of SynchronizeDirectories. While you pass it as 5th argument.
http://winscp.net/eng/docs/library_session_synchronizedirectories
Advertisements

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!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License