Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

File Server

Simple file server built with Go and Cobra with support for multiple media formats and HTTPS.

Installation

With go install

go install github.com/alireza-hmd/fileserver@latest

From Source

git clone https://github.com/alireza-hmd/fileserver
cd fileserver
go mod download
go build -o fileserver

Usage

Basic Usage

Serve current directory on port 8080:

fileserver

Serve specific directory:

fileserver /path/to/directory

Serve current directory on custom port:

fileserver --port 3000

HTTPS Mode

Using Auto-Generated Certificates

fileserver --https --gen-cert

This will:

  • Generate a self-signed certificate valid for 1 year
  • Save certificates to ./certs/ directory
  • Enable HTTPS on the specified port

Using Custom Certificates

fileserver --https --cert /path/to/cert.pem --key /path/to/key.pem

Command Line Options

Usage:
  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

Examples

Example 1: Basic File Server

# Serve current directory on port 8080
fileserver

# Access at: http://localhost:8080

Example 2: Media Server with HTTPS

# Serve media directory with auto-generated HTTPS
fileserver /home/user/media --port 443 --https --gen-cert

# Access at: https://localhost:443

Example 3: Document Server with Custom Port

# Serve documents directory on port 3000
fileserver /home/user/documents --port 3000

# Access at: http://localhost:3000

Example 4: Basic File Server Without Logging

# Serve current directory on port 8080 without logging
fileserver --log none

# Access at: http://localhost:8080

Security Features

Path Traversal Protection

  • Prevents ../ attacks
  • Blocks access to hidden files (starting with .)
  • Ensures files are served only from the specified directory

HTTPS Configuration

  • Support for custom TLS certificates
  • Generation of self-signed certificates

Certificate Management

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:

  • localhost in DNS names
  • 127.0.0.1 and ::1 in IP addresses

Troubleshooting

Common Issues

  1. Permission Denied

    # Make sure you have read permissions for the directory
    chmod -R +r /path/to/directory
  2. Port Already in Use

    # Use a different port
    ./fileserver --port 8081
  3. HTTPS Certificate Issues

    # Regenerate certificates
    rm -rf certs/
    ./fileserver --https --gen-cert
  4. File Not Found (404)

    • Check file permissions
    • Verify the file path is correct
    • Ensure no hidden file access attempts

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages