Simple file server built with Go and Cobra with support for multiple media formats and HTTPS.
go install github.com/alireza-hmd/fileserver@latestgit clone https://github.com/alireza-hmd/fileserver
cd fileserver
go mod download
go build -o fileserverServe current directory on port 8080:
fileserverServe specific directory:
fileserver /path/to/directoryServe current directory on custom port:
fileserver --port 3000fileserver --https --gen-certThis will:
- Generate a self-signed certificate valid for 1 year
- Save certificates to
./certs/directory - Enable HTTPS on the specified port
fileserver --https --cert /path/to/cert.pem --key /path/to/key.pemUsage:
fileserver [directory] [flags]
Flags:
-p, --port int Port to serve on (default 8080)
--https Enable HTTPS
--gen-cert Generate TLS certificates
--cert string Path to TLS certificate file
--key string Path to TLS private key file
--log string Log level (none, info, debug) (default "info")
-h, --help Help for fileserver
# Serve current directory on port 8080
fileserver
# Access at: http://localhost:8080# Serve media directory with auto-generated HTTPS
fileserver /home/user/media --port 443 --https --gen-cert
# Access at: https://localhost:443# Serve documents directory on port 3000
fileserver /home/user/documents --port 3000
# Access at: http://localhost:3000# Serve current directory on port 8080 without logging
fileserver --log none
# Access at: http://localhost:8080- Prevents
../attacks - Blocks access to hidden files (starting with
.) - Ensures files are served only from the specified directory
- Support for custom TLS certificates
- Generation of self-signed certificates
When using --gen-cert, certificates are stored in:
./certs/
├── server.crt # Certificate file
└── server.key # Private key file
Certificates are valid for 1 year and include:
localhostin DNS names127.0.0.1and::1in IP addresses
-
Permission Denied
# Make sure you have read permissions for the directory chmod -R +r /path/to/directory -
Port Already in Use
# Use a different port ./fileserver --port 8081 -
HTTPS Certificate Issues
# Regenerate certificates rm -rf certs/ ./fileserver --https --gen-cert -
File Not Found (404)
- Check file permissions
- Verify the file path is correct
- Ensure no hidden file access attempts