Powershell SystemFileWatcher does not trigger Event

Get help for specific problems
Posts: 1
Joined: 2 Dec 2019

regionfive

I am using FreeFileSync to Sync an SFTP with a loal folder. I am running a Powershell script, that has a SystemFileWatcher to listen whether a new file was created at the local folder. It works fine when dropping files there locally, but it does not trigger an event, when new files arrived through an ffs_batch. Has anyone ideas why it behaves like that?
Thank You.
Posts: 7
Joined: 28 Nov 2019

kolos123

I recommend you check your watcher configuration.
As to your case, I had setup a SFTP server and a local folder. Then, I used the following code:
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = "c:\test1"
$watcher.Filter = "*.*"
$watcher.IncludeSubdirectories = $true
$watcher.EnableRaisingEvents = $true
$action = {$path = $Event.SourceEventArgs.FullPath
$changeType= $Event.SourceEventArgs.ChangeType
$logLine = "$(Get-Date), $changeType,$path"
Add-Content "C:\log2.txt" -value $logLine}
$created = Register-ObjectEvent $watcher Created -Action $action
I tested it out with two text files:
-testfile1.txt
-testfile2.txt

After running the batch file, creation logs appeared for two ffs_tmp files.

I hope this answer satisfies you