transerOptions.FileMask does not work

Advertisement

bartplessers
Guest

transerOptions.FileMask does not work

Hello,

I'm trying to sync my windows phone FTP server to localdisk.
I'm using PowerShell (windows 10)
and WinSCP-5.9.1-Automation

The main part of my script:

$session.add_FileTransferred( { FileTransferred($_) } )

# Connect
$session.Open($sessionOptions)

$transferoptions = New-Object WinSCP.TransferOptions
# $transferOptions.FileMask = "*>2016-O8-01"
$transferoptions.FileMask = ".txt"


# Synchronize files
$synchronizationResult = $session.SynchronizeDirectories([WinSCP.SynchronizationMode]::Local, $FTPLocalFolder, $FTPRemoteFolder, $false, $transferoptions)

# Throw on any error
$synchronizationResult.Check()


At the end, I only want to sync files where dateModified > 2016-08-01. This filemask didn't work, so I tried with FileMask = ".txt", but this didn't work either: all files are synchronized, no matter what the extension is.

What do I wrong?

Kind regards,
Bart

Reply with quote

Advertisement

elmariachi
Joined:
Posts:
4
Location:
UK

Re: transerOptions.FileMask does not work

I'm sure I'm missing something here, but how are arguments for TransferOptions actually handled? I've been through the documentation and just can't figure it out in my script - if I include any more than five arguments when using SynchronizeDirectories in a powershell script, I get an error stating 'Error: Cannot find an overload for "SynchronizeDirectories" and the argument count: "6".'.

I'm trying to exclude certain file types (executables) from download via SFTP and also set it to auto resume. The section of the script in question is;

try
{
# Will continuously report progress of synchronization
$session.add_FileTransferred( { FileTransferred($_) } )

# Connect
$session.Open($sessionOptions)

#Transfer options
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.ResumeSupport.State = [WinSCP.TransferResumeSupportState]::On
$file_mask = "*.* | .exe"
$transferOptions.FileMask = $file_mask

# Synchronize files
$synchronizationResult = $session.SynchronizeDirectories(
[WinSCP.SynchronizationMode]::Local, "c:\test", "/test/", $False, $SynchronizationCriteria.Size, $transferOptions)

#Compare files based on file size
#$SynchronizationCriteria.Size

# Throw on any error
$synchronizationResult.Check()
}


Any pointers would be very much appreciated.

Reply with quote

elmariachi
Joined:
Posts:
4
Location:
UK

Worked it out just after posting;

# Connect
$session.Open($sessionOptions)

#Transfer options
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.ResumeSupport.State = [WinSCP.TransferResumeSupportState]::On
$file_mask = "| *.exe;*.bat;*."
$transferOptions.FileMask = $file_mask

# Synchronize files
$synchronizationResult = $session.SynchronizeDirectories(
[WinSCP.SynchronizationMode]::Local, "c:\test", "/test/", $False, $False, [WinSCP.SynchronizationCriteria]::Size, $transferOptions)

# Throw on any error
$synchronizationResult.Check()

I didn't realise that my synchronisation criteria syntax was wrong and this seemed to be interfering with the rest of it.

Still can't get logging working though - using this entry;

$session = New-Object WinSCP.Session
$session.SessionLogPath = "C:\scripts\logs\script.xml"
$session.Open($sessionOptions)

...but not sure where to put it in the script. Have tried several options but, although it doesn't throw an error, it also doesn't create a log file.

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
40,476
Location:
Prague, Czechia

elmariachi wrote:

Still can't get logging working though - using this entry;

$session = New-Object WinSCP.Session
$session.SessionLogPath = "C:\scripts\logs\script.xml"
$session.Open($sessionOptions)

...but not sure where to put it in the script. Have tried several options but, although it doesn't throw an error, it also doesn't create a log file.
You cannot use .xml for a session log file. Use for example .log.

Reply with quote

Advertisement

Advertisement

You can post new topics in this forum