A simple HTTP file server written in Go that allows you to upload, download, list, and delete files through a web interface.
- 📤 Upload files via web interface or curl
- 📥 Download files with a single click
- 📋 List all files with size and modification time
- 🗑️ Delete files (optional)
- 📊 Human-readable file sizes
- 🔒 Safe filename handling
- 💾 Support for large file uploads (configurable)
- 🎯 Proper HTTP status codes for both browser and curl users
fsrv/
├── cmd/
│ └── fsrv/
│ └── main.go # Main application entry point
├── internal/
│ ├── config/ # Configuration management
│ │ ├── config.go
│ │ └── config_test.go
│ ├── handler/ # HTTP request handlers
│ │ ├── handler.go
│ │ └── handler_test.go
│ ├── service/ # Business logic layer
│ │ ├── errors.go
│ │ ├── service.go
│ │ └── service_test.go
│ └── util/ # Utility functions
│ ├── util.go
│ └── util_test.go
├── web/
│ ├── templates/ # HTML templates
│ │ ├── files.html
│ │ ├── info.html
│ │ └── upload.html
│ └── fs.go # Embedded filesystem
├── Makefile
├── go.mod
├── go.sum
├── README.md
└── .gitignore
# Clone the repository
git clone https://github.com/zxpbenson/fsrv.git
cd fsrv
# Build using Makefile
make build
# Run the application
./build/fsrvgo build -o build/fsrv ./cmd/fsrvgo install github.com/zxpbenson/fsrv/cmd/fsrv@latest./fsrv [options]Options:
-p <port>: Specify the port to listen on (default: 8080)-d: Enable delete file by UI (default: false)-s <directory>: Specify the directory to store files (default: ./store)-n <hostname>: Specify the server name (default: system hostname)-m <size>: Max file size to upload in bits (default: 32, which means 1<<32 = 4GB)
Start server on port 8080:
./fsrvStart server on port 3000 with delete enabled:
./fsrv -p 3000 -dStart server with custom store directory:
./fsrv -s /path/to/storeStart server with max file size of 8GB:
./fsrv -m 33GET /orGET /files: List all filesGET /toUpload: Show upload pagePOST /upload: Upload a fileGET /download?file=<filename>: Download a fileGET /del?file=<filename>: Delete a file (if enabled)
FSrv is designed to serve both browser users (who see HTML pages) and curl/script users (who rely on HTTP status codes to determine success or failure). All endpoints return proper HTTP status codes:
| Status Code | Meaning | Example |
|---|---|---|
| 200 | Success | File uploaded/downloaded/deleted/listed successfully |
| 400 | Bad Request | Attempted to download/delete a directory |
| 404 | Not Found | File does not exist |
| 405 | Method Not Allowed | Used POST on a GET endpoint (or vice versa) |
| 409 | Conflict | Uploaded a file that already exists |
| 413 | Request Entity Too Large | File exceeds the configured max size |
| 500 | Internal Server Error | Server-side I/O failure |
This makes it easy for curl users to check results programmatically:
# Upload and check status
HTTP_CODE=$(curl -s -o /dev/null -w '%{http_code}' -F 'file=@test.txt' http://localhost:8080/upload)
if [ "$HTTP_CODE" -eq 200 ]; then
echo "Upload succeeded"
elif [ "$HTTP_CODE" -eq 409 ]; then
echo "File already exists"
fi
# Download with error handling
curl -f -o 'file.txt' 'http://localhost:8080/download?file=file.txt' || echo "Download failed"- Open
http://localhost:8080/toUploadin your browser - Select a file and click "Upload"
curl -F 'file=@/path/to/file' http://localhost:8080/upload- Open
http://localhost:8080/filesin your browser - Click on the file you want to download
curl -L -o 'filename' 'http://localhost:8080/download?file=filename'- Open
http://localhost:8080/filesin your browser - Click the "Delete" button next to the file (if delete is enabled)
curl 'http://localhost:8080/del?file=filename'This project includes a Makefile to simplify common development tasks.
make test
# Run tests with coverage report
make test-coverage# Format code
make fmt
# Run linter
make lint
# Run vet
make vetmake build# Build and run
make run
# Or run directly from build
./build/fsrvmake clean# Build all platforms (Linux/Windows/macOS)
make cross-compile
# Build for a specific platform
make cross-compile GOOS=linux GOARCH=arm64
make cross-compile GOOS=windows GOARCH=amd64The application follows a clean architecture pattern:
- Config Layer: Handles configuration parsing and management
- Service Layer: Contains business logic for file operations
- Handler Layer: Handles HTTP requests and responses
- Util Layer: Provides utility functions for common operations
MIT License
Contributions are welcome! Please feel free to submit a Pull Request.