Topic "Powershell Filemask not working Synchronize directories"

Author Message
smartel
[View user's profile]

Joined: 2014-07-25
Posts: 3
Good day All!

I am trying to synchronize directories, including only files starting with Backup_ , with a powershell script, but it seems to ignore my filemask, here it is, any help welcome!:

[Reflection.Assembly]::LoadFrom("\\d:\temp\WinSCPnet.dll") | Out-Null

# Main script
try
{
$sessionOptions = New-Object WinSCP.SessionOptions
$sessionOptions.Protocol = [WinSCP.Protocol]::Sftp
$sessionOptions.HostName = "sftpserver"
$sessionOptions.PortNumber = "222"
$sessionOptions.UserName = "ftpusername"
$sessionOptions.Password = "pwd"
$sessionOptions.SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"


$session = New-Object WinSCP.Session
try
{
# Connect
$session.Open($sessionOptions)
$transferoptions= New-Object WinSCP.TransferOptions
$TransferOptions.FileMask = "Backup_*.zip|*/"
# Synchronize files
$synchronizationResult = $session.SynchronizeDirectories(
[WinSCP.SynchronizationMode]::Remote, "d:\temp", "/", $True, $transferoptions)

# Throw on any error
$synchronizationResult.Check()
}
finally
{
# Disconnect, clean up
$session.Dispose()
}

exit 0
}
catch [Exception]
{
Write-Host $_.Exception.Message
exit 1
}
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.
_________________
Martin Prikryl
smartel
[View user's profile]

Joined: 2014-07-25
Posts: 3
Here is the log file,

Thanks!
winscp.log (31.25 KB) Private file

Description: (none)

martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
You are passing $transferoptions to mirror parameter of Session.SynchronizeDirectories method, not to the correct options parameter. See syntax at:
http://winscp.net/eng/docs/library_session_synchronizedirectories
smartel
[View user's profile]

Joined: 2014-07-25
Posts: 3
Thanks!

Makes sense, here is what I use if others can use it, the 1 in there is to use the time option for criteria, did not find a nicer way to pass it on!, but it works !:

.
.
$synchronizationResult = $session.SynchronizeDirectories(
[WinSCP.SynchronizationMode]::Remote, "d:\temp", "/", $True, $False, 1, $TransferOptions)
.
.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
smartel wrote:
the 1 in there is to use the time option for criteria, did not find a nicer way to pass it on!

Use [WinSCP.SynchronizationCriteria]::Time, the same syntax you are using for SynchronizationMode and Protocol already.
See http://winscp.net/eng/docs/library_powershell#enums
_________________
Martin Prikryl
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