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: Powershell Filemask not working Synchronize directories

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 https://winscp.net/eng/docs/library_powershell#enums
smartel

Re: Powershell Filemask not working Synchronize directories

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)
.
.
smartel

Re: Powershell Filemask not working Synchronize directories

Here is the log file,

Thanks!
martin

Re: Powershell Filemask not working Synchronize directories

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.
smartel

Powershell Filemask not working Synchronize directories

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
}