What are some free and portable web server options that can run from PowerShell?
Asked by
~missing page
I'm looking for a way to push about 2GB of data to multiple Windows 10 workstations and need a simple web server to host that data. This server needs to run silently using PowerShell because there's a specific application that requires it to serve the files (the app runs with the command `app.exe -url http://localhost/data`). Unfortunately, I can't make the app reference the local path directly (like `C:data`), so a web server is necessary.
I want to transfer the files and then run the web server automatically once everything is copied to `C:data`, followed by starting the app and using the hosted data. I've found some options, but they're either not free or they require a GUI, which I want to avoid. Any recommendations that are trustworthy?
Answers
If you need a quick solution, using Python is easy! You can set up a simple HTTP server with just the command `python3 -m http.server`. It's great for serving files without any graphical interface. Just make sure Python is installed on your workstations.
Reply to this answer
You might also want to consider using .NET's built-in server in PowerShell. Hereโs a small script you can run:
```powershell
$httpListener = New-Object System.Net.HttpListener
$httpListener.Prefixes.Add("http://localhost:8080/")
$httpListener.Start()
try {
while ($true) {
$context = $httpListener.GetContext()
$response = $context.Response
$responseString = "File served!"
$buffer = [System.Text.Encoding]::UTF8.GetBytes($responseString)
$response.ContentLength64 = $buffer.Length
$response.OutputStream.Write($buffer, 0, $buffer.Length)
$response.Close()
}
}
finally {
if ($httpListener.IsListening) {
$httpListener.Stop()
}
}
```
This runs a basic server that listens for requests.
!pitchA4: Does this require admin rights to set up?
Mallow: It usually won't need admin rights if you're listening on localhost only.
Reply to this answer
You can actually run IIS on Windows 10 using PowerShell. Hereโs a quick script you can use:
```powershell
Enable-WindowsOptionalFeature -online -featurename IIS-WebServerRole,IIS-WebServer,IIS-StaticContent,IIS-ManagementConsole -All -NoRestart
Import-Module WebAdministration
New-Website -Name "data" -PhysicalPath c:data -Port 8080 -Force
Start-Website -Name "data"
```
This sets up a lightweight server that only runs locally if you want. Just remember that you can disable it later too if needed!
BreadthFirst: Remember to make sure only localhost can access it for security.
proof.of.delivery: IIS is a solid choice because it receives regular updates from Windows.
Reply to this answer
I used a lightweight web server called HFS (HTTP File Server). Itโs command line only, and does the job quickly. Check it out [here](https://rejetto.com/hfs/).
Reply to this answer
Add your answer
Answers are reviewed before publication.
archivist+on+leave: This is definitely the simplest solution I've seen!
sitting_near_the_window: Thanks for the tip! I'll give it a try.