LinuxCommandLibrary

http-server-upload

Serve files via simple HTTP server, upload enabled

TLDR

Start an HTTP server on the default port to upload files to the current directory

$ http-server-upload
copy

Start an HTTP server with the specified maximum allowed file size for uploads in MiB (defaults to 200 MiB)
$ MAX_FILE_SIZE=[size_in_megabytes] http-server-upload
copy

Start an HTTP server on a specific port to upload files to the current directory
$ PORT=[port] http-server-upload
copy

Start an HTTP server, storing the uploaded files in a specific directory
$ UPLOAD_DIR=[path/to/directory] http-server-upload
copy

Start an HTTP server using a specific directory to temporarily store files during the upload process
$ UPLOAD_TMP_DIR=[path/to/directory] http-server-upload
copy

Start an HTTP server accepting uploads with a specific token field in the HTTP post
$ TOKEN=[secret] http-server-upload
copy

SYNOPSIS

http-server-upload [-p PORT] [-b ADDRESS] [-d DIRECTORY]

PARAMETERS

-p, --port PORT
    Port to listen on (default: 8080)

-b, --bind ADDRESS
    Interface to bind to (default: 0.0.0.0)

-d, --dir DIRECTORY
    Directory to serve and store uploads (default: current)

-a, --auth USER:PASS
    Enable basic HTTP authentication

-l, --loglevel LEVEL
    Set logging verbosity (debug/info/error)

-h, --help
    Show help and exit

--version
    Print version information

DESCRIPTION

The http-server-upload command launches a lightweight HTTP server designed specifically for uploading files to a local directory via web browser or tools like curl. It serves files from the specified directory and handles HTTP PUT or POST requests for uploads, making it ideal for quick file sharing in development, testing, or ad-hoc transfers.

Users access it by opening a browser to the server's address (e.g., http://localhost:8080), where an upload form or direct PUT endpoint is available. Uploaded files are stored in the target directory, with basic listing support. It's not intended for production due to lacking authentication, HTTPS, or advanced security features.

This tool is particularly useful for developers needing to upload assets to a server without complex setup, or for sharing large files on local networks. It supports resuming uploads in some implementations and provides console logging for requests. Default port is 8080, and it binds to all interfaces unless specified otherwise.

CAVEATS

Not production-ready: no HTTPS, weak auth, vulnerable to unrestricted uploads. Use firewall and run as non-root. May conflict with other services on port 8080.

UPLOAD EXAMPLE

curl -T file.txt http://localhost:8080/uploads/
Or browser: Visit http://<ip>:8080 and use form.

SECURITY NOTE

Always restrict --bind to localhost for untrusted networks. Disable directory listing if not needed.

HISTORY

Originated as a Node.js module (http-server) around 2010, with upload extensions added later. Linux binaries via npm or packages like node-http-server-upload since ~2015. Focuses on simplicity over features.

SEE ALSO

python3 -m http.server(1), busybox httpd(8), nginx(8), lighttpd(8)

Copied to clipboard