Load balancing FileZilla server on Windows

Need help with FileZilla Server? Something does not work as expected? In this forum you may find an answer.

Moderator: Project members

Post Reply
Message
Author
CDevops
500 Command not understood
Posts: 2
Joined: 2016-05-13 20:08
First name: Devops
Last name: Department

Load balancing FileZilla server on Windows

#1 Post by CDevops » 2016-05-13 20:54

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"}
Last edited by CDevops on 2016-05-14 01:24, edited 1 time in total.

User avatar
botg
Site Admin
Posts: 35491
Joined: 2004-02-23 20:49
First name: Tim
Last name: Kosse

Re: Load balancing FileZilla server on Windows

#2 Post by botg » 2016-05-13 21:46

I like this solution.

User avatar
boco
Contributor
Posts: 26899
Joined: 2006-05-01 03:28
Location: Germany

Re: Load balancing FileZilla server on Windows

#3 Post by boco » 2016-05-13 23:19

Wow, Admin approved. :wink:

I'll stick it for a while.
### BEGIN SIGNATURE BLOCK ###
No support requests per PM! You will NOT get any reply!!!
FTP connection problems? Please do yourself a favor and read Network Configuration.
FileZilla connection test: https://filezilla-project.org/conntest.php
### END SIGNATURE BLOCK ###

CDevops
500 Command not understood
Posts: 2
Joined: 2016-05-13 20:08
First name: Devops
Last name: Department

Re: Load balancing FileZilla server on Windows

#4 Post by CDevops » 2016-05-14 01:27

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!

DuncanPatt
500 Command not understood
Posts: 1
Joined: 2016-07-27 15:56
First name: Duncan
Last name: Pattinson
Location: Manchester

Re: Load balancing FileZilla server on Windows

#5 Post by DuncanPatt » 2016-07-27 16:02

spot on solution -many thanks

Buzzy
500 Command not understood
Posts: 1
Joined: 2017-04-15 11:58
First name: Buzzy
Last name: Series

Re: Load balancing FileZilla server on Windows

#6 Post by Buzzy » 2017-04-15 12:04

Wow! Thanks admin.

Post Reply