Simple HTTP file server with automatic port conflict resolution
📁 A Rust-based HTTP service that serves files from the executable directory, automatically handles port conflicts
Features • Quick Start • Installation • Usage
- 🚀 Auto Port Conflict Resolution - Automatically detects and terminates processes occupying the target port
- 📁 File Server - Serves static files from the executable directory
- 🌍 IPv4/IPv6 Support - Checks both IPv4 and IPv6 port bindings
- 💾 Built with Rust - Type-safe, memory-safe, and fast
- 🔒 Windows Process Management - Uses Windows API for reliable process termination
- 📝 Structured Logging - Clear logs for debugging and monitoring
- ⚡ Lightweight - Single binary, no runtime dependencies
# Build the project
cd port-manager
cargo build --release
# Run the HTTP server
./target/release/port-manager.exe
# Access files
curl http://localhost:8080/yourfile.txtThat's it! The server will automatically resolve port conflicts if port 8080 is already in use. 🎉
Download the compiled binary from the target/release/ directory:
# The release binary is located at:
port-manager/target/release/port-manager.exegit clone <your-repo-url>
cd port-manager
cargo build --release# Run the server (default port: 8080)
./port-manager.exe
# The server will:
# 1. Check if port 8080 is occupied
# 2. Terminate any process occupying the port
# 3. Start HTTP service on port 8080
# 4. Serve files from the executable directory# Root endpoint
curl http://localhost:8080/
# Health check
curl http://localhost:8080/health
# Access a file in the executable directory
curl http://localhost:8080/Cargo.toml
# Access via /files/ prefix (alternative)
curl http://localhost:8080/files/Cargo.toml| Endpoint | Description |
|---|---|
/ |
Returns "Port Manager HTTP Service" |
/health |
Returns JSON with status and start time |
/files/* |
Serves static files from exe directory |
/* |
Fallback route, serves files directly |
| Variable | Description |
|---|---|
RUST_LOG=info |
Enable info-level logging (default) |
RUST_LOG=debug |
Enable debug-level logging |
RUST_LOG=warn |
Enable only warnings |
RUST_LOG=error |
Enable only errors |
- Port Detection - Queries Windows TCP table to check if port 8080 is in use
- Process Termination - If occupied, identifies and terminates the owning process
- Service Start - Initializes the HTTP server
- File Serving - Serves files from the executable's directory
The server uses Windows GetExtendedTcpTable API to:
- Query all IPv4 and IPv6 TCP connections
- Find processes listening on the target port (state = LISTEN)
- Terminate those processes using
TerminateProcess
- Uses native Windows APIs for accurate port and process information
- Handles both IPv4 and IPv6 bindings
- Waits 1 second after termination for port cleanup
- Gracefully handles Ctrl+C shutdown
- Rust 1.70 or later
- Windows OS (uses Windows-specific APIs)
- Cargo
# Debug build
cargo build
# Release build (optimized)
cargo build --release
# Run tests
cargo test
# Run with logging
RUST_LOG=debug cargo runThe release binary will be at target/release/port-manager.exe.
Files are served from the executable directory - the directory containing the port-manager.exe file.
port-manager/
├── port-manager.exe
├── Cargo.toml
├── README.md
└── data/
└── myfile.txt
With the above structure:
http://localhost:8080/Cargo.toml→ servesCargo.tomlhttp://localhost:8080/data/myfile.txt→ servesdata/myfile.txthttp://localhost:8080/files/Cargo.toml→ also servesCargo.toml
This tool includes safety features:
- ✅ Graceful Shutdown - Handles Ctrl+C properly
- ✅ Error Handling - Continues even if process termination fails
- ✅ Type-Safe - Built with Rust for memory safety
- ✅ Port Cleanup Wait - Waits 1 second after termination
- ✅ Open Source - Fully auditable code
This project is provided as-is for use in your own projects.
- Built with Rust
- Web framework powered by Axum
- Async runtime by Tokio
- Process management using windows-rs
- Logging with tracing
Made with 🦀 and Rust