Skip to content

zxpbenson/fsrv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

22 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

FSrv - Simple File Server

A simple HTTP file server written in Go that allows you to upload, download, list, and delete files through a web interface.

Features

  • πŸ“€ 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)

Project Structure

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
β”‚   β”‚   β”œβ”€β”€ 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

Installation

Build from source

# Clone the repository
git clone https://github.com/zxpbenson/fsrv.git
cd fsrv

# Build using Makefile
make build

# Run the application
./build/fsrv

Manual Build

go build -o build/fsrv ./cmd/fsrv

Using go install

go install github.com/zxpbenson/fsrv/cmd/fsrv@latest

Usage

Command Line Options

./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)

Examples

Start server on port 8080:

./fsrv

Start server on port 3000 with delete enabled:

./fsrv -p 3000 -d

Start server with custom store directory:

./fsrv -s /path/to/store

Start server with max file size of 8GB:

./fsrv -m 33

API Endpoints

  • GET / or GET /files: List all files
  • GET /toUpload: Show upload page
  • POST /upload: Upload a file
  • GET /download?file=<filename>: Download a file
  • GET /del?file=<filename>: Delete a file (if enabled)

Upload Files

Via Web Interface

  1. Open http://localhost:8080/toUpload in your browser
  2. Select a file and click "Upload"

Via curl

curl -F 'file=@/path/to/file' http://localhost:8080/upload

Download Files

Via Web Interface

  1. Open http://localhost:8080/files in your browser
  2. Click on the file you want to download

Via curl

curl -L -o 'filename' 'http://localhost:8080/download?file=filename'

Delete Files

Via Web Interface

  1. Open http://localhost:8080/files in your browser
  2. Click the "Delete" button next to the file (if delete is enabled)

Via curl

curl 'http://localhost:8080/del?file=filename'

Development

This project includes a Makefile to simplify common development tasks.

Running tests

make test

# Run tests with coverage report
make test-coverage

Code Quality

# Format code
make fmt

# Run linter
make lint

# Run vet
make vet

Building

make build

Running

# Build and run
make run

# Or run directly from build
./build/fsrv

Cleaning

make clean

Cross Compilation

Build for multiple platforms (Linux/Windows/macOS) at once:

make cross-compile

Architecture

The 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

License

MIT License

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

About

simple file serverA lightweight HTTP file server written in Go with web interface for uploading, downloading, listing, and deleting files.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors