Page 1 of 1

Load balancing FileZilla server on Windows

Posted: 2016-05-13 20:54
by CDevops
We looked all over for some references on how to keep two instances of Filezilla in sync, but nothing seemed to be quite what we needed. In the end with a little powershell scripting and some new found knowledge of Filezilla command arguments, we created a Windows scheduled task that keeps the Filezilla settings and user accounts in sync between two machines, automatically and instantly. I assume it requires at least .net 2.0, which this version and higher is part of all Windows Server OS's for a while now.

Enjoy!

Code: Select all

##############################################################################################################
#                                                                                                            #
#						Name: gw_filezilla_settings_sync													 #
#					 	Purpose: Copies FileZilla settings from one GW server to the other, if changed		 #
#						Created By: MJ 05/13/2016														 #
#                                                                                                            #
#Script makes use of: https://gallery.technet.microsoft.com/scriptcenter/Powershell-FileSystemWatche-dfd7084b#
#                                                                                                            #
#                                                                                                            #
##############################################################################################################


#Kill all other instances of script
$powershellKill = Get-WmiObject Win32_Process -Filter "Name='powershell.exe' AND NOT ProcessId LIKE '$pid'"
$powershellKill = $powershellKill.ProcessID

$powershellKill

foreach ($procid in $powershellKill) {
	Stop-Process $procid -Force
	}

Write-Output "Starting" | Out-File -FilePath C:\DevOps\Logs\gw_filezilla_settings_sync.txt

# To stop the monitoring, run the following commands:
$event = Get-EventSubscriber
$event = $event.SourceIdentifier
if ($event -eq "Filezilla_Changed") {
    Unregister-Event Filezilla_Changed
    }

$localFolder = 'C:\Program Files (x86)\FileZilla Server' # Enter the root path you want to monitor.
$filter = '*.xml'  # You can enter a wildcard filter here.

# In the following line, you can change 'IncludeSubdirectories to $true if required.                          
$fsw = New-Object System.IO.FileSystemWatcher $localFolder, $filter -Property @{IncludeSubdirectories = $false;NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'}

Register-ObjectEvent $fsw Changed -SourceIdentifier Filezilla_Changed -Action {
$name = $Event.SourceEventArgs.Name
$changeType = $Event.SourceEventArgs.ChangeType
$timeStamp = $Event.TimeGenerated

$hostName = $env:computername

if ($hostName -eq "Server01") {
    $remoteHost = "Server02"
    }

if ($hostName -eq "Server02") {
    $remoteHost = "Server01"
    }  

$localFolder = 'C:\Program Files (x86)\FileZilla Server' 
$remoteFolder = "\\$remoteHost\C$\Program Files (x86)\FileZilla Server"

Copy-Item "$localFolder\$name" "$remoteFolder\$name" -Force

#Invoke-Command
Invoke-Command -ComputerName $remoteHost -ScriptBlock { & cmd.exe /c '"C:\Program Files (x86)\FileZilla Server\FileZilla Server.exe" /reload-config' }


Out-File -FilePath C:\DevOps\Logs\gw_filezilla_settings_sync.txt -Append -InputObject "The file '$name' was $changeType at $timeStamp"}

Re: Load balancing FileZilla server on Windows

Posted: 2016-05-13 21:46
by botg
I like this solution.

Re: Load balancing FileZilla server on Windows

Posted: 2016-05-13 23:19
by boco
Wow, Admin approved. :wink:

I'll stick it for a while.

Re: Load balancing FileZilla server on Windows

Posted: 2016-05-14 01:27
by CDevops
FYI, I found a few bugs that needed tweaked. The updated copy runs properly as a Windows Scheduled task. You'll probably need to add a switch for -ExecutionPolicy Bypass, we actually digitally singed ours to avoid bypassing our policy.

Behavior confirmed, open FZS1 edit a user, open FZS2 go to users and the change is there. We also decided to do a master slave configuration and will only make adjustments on one server to prevent the possibility of file conflicts.

Enjoy!

Re: Load balancing FileZilla server on Windows

Posted: 2016-07-27 16:02
by DuncanPatt
spot on solution -many thanks

Re: Load balancing FileZilla server on Windows

Posted: 2017-04-15 12:04
by Buzzy
Wow! Thanks admin.