Script to prevent Windows Server from sleeping when Infuse is open

I have long been struggling with a sleep mode issue when using an FTP server on my Windows Media Server. In some scenarios Infuse would completely cache the media I chose to watch in its entirety, then whilst I was watching it my media server would go to sleep due to their being no traffic, it means I would have to set a super long sleep timer on my server to avoid this scenario. I recently have been trying to save some pennies with our power bill so wanted to run a short sleep timer.

Infuse is apparently supposed to keep your server awake whilst Infuse is open but this wasn’t working for me and my FileZilla FTP client, although an idle connection would exist for infuse on my FTP server because no traffic was passing the Windows server would sleep, sometimes before the next episode would start and therefore Infuse would time out. I finally found a fix.

Basically a script located on a very old post from FileZilla forums and all it does is run constantly in a bat file and will set your sleep time to 0 if there is an established connection on port 21, then when there is no connection on port 21 (when you exit out of infuse) it will the loop around the script and set the sleep timer to what ever you like, it is set to 20 below.

Taking no credit for this, I just finally found it after trawling the internet:

https://forum.filezilla-project.org/viewtopic.php?f=6&t=12534&p=110724#p110724


@echo off

netstat -an | find ":21 " | find “ESTABLISHED” >nul
if not ERRORLEVEL 1 goto ACTIVE
goto IDLE

:LOOP_IDLE
timeout /t 60 /nobreak >nul
netstat -an | find ":21 " | find “ESTABLISHED” >nul
if not ERRORLEVEL 1 goto ACTIVE
echo|set /p=-
goto LOOP_IDLE

:LOOP_ACTIVE
timeout /t 60 /nobreak >nul
netstat -an | find ":21 " | find “ESTABLISHED” >nul
if ERRORLEVEL 1 goto IDLE
echo|set /p=+
goto LOOP_ACTIVE

:IDLE
powercfg -x standby-timeout-ac 20
echo|set /p=-
goto LOOP_IDLE

:ACTIVE
powercfg -x standby-timeout-ac 0
echo|set /p=+
goto LOOP_ACTIVE


So you could even set your sleep timer to 1 if you wanted a super aggressive profile, what I have done is add it to the Windows Task Scheduler to run the script ‘At Start up’, this way it runs even if no one is even logged on and seeing as my FTP server runs as a service its all good.

Anyway, maybe this will help someone else in the same boat.

2 Likes

A post was merged into an existing topic: WOL Feature only sends packet on Client App startup