How to Solve "Cannot Bind to Port Due to Permission Denied" on Windows
A few months ago I started having trouble where ZitaFTP Server sometimes wouldn't be able to bind to its data ports. The error was confusing: "permission denied."
Click here to watch the video on Odysee.
Permission denied? What? The error would be "port in use" if another program was using it. What's going on?
The Problem: Hyper-V
The problem started after I installed Hyper-V. Ironically, this was to test ZitaFTP Server on different versions of Windows without needing multiple computers.
Anyway, it turns out that Hyper-V reserves some port ranges. It seems to be semi-random because the port ranges change after every reboot. While Hyper-V never reserves predefined ports such as for HTTP (port 80) or HTTPS (port 443), it was regularly reserving the ports that I chose to be the FTP data connection ports.
I tried multiple suggestions that were found on the internet. Most didn't work. The one that did can be found on this StackOverflow page. No, not the accepted answer (the one with the green tick); that one failed. You have to scroll down a bit further. The solution was:
Open a shell window as administrator (type "CMD" in the start menu search, right-click, and select "run as administrator")
Then enter the following two commands:
net stop winnat
net start winnat
This clears the reserved ports. It works every time.
It's not a perfect solution, because you have to do this every time that your chosen ports get reserved. I wish I could tell it "don't touch this port range." If you know how to do that, please let me know (leave a comment below or contact me here). Otherwise, my recommendation is to use the solution above. Of course, feel free to try the other suggestions. One of those may work for you even if they didn't work for me.
Post your comment