GithubHelp home page GithubHelp logo

noobcode73 / http-file-server Goto Github PK

View Code? Open in Web Editor NEW

This project forked from muller2002/http-file-server

0.0 0.0 0.0 705 KB

tiny portable HTTP file server. single binary, no dependencies. linux, osx, windows. #golang

License: MIT License

Go 54.75% Makefile 6.57% HTML 38.68%

http-file-server's Introduction

http-file-server

http-file-server is a dependency-free HTTP file server. Beyond directory listings and file downloads, it lets you download a whole directory as .zip or .tar.gz (generated on-the-fly).

screenshot

Contents

Examples

Serving a path at /

$ http-file-server /tmp
2018/11/13 23:00:03 serving local path "/tmp" on "/tmp/"
2018/11/13 23:00:03 redirecting to "/tmp/" from "/"
2018/11/13 23:00:03 http-file-server listening on ":8080"

Serving $PWD at /

$ cd /tmp
$ http-file-server
2018/12/13 03:18:00 serving local path "/tmp" on "/tmp/"
2018/12/13 03:18:00 redirecting to "/tmp/" from "/"
2018/12/13 03:18:00 http-file-server listening on ":8080"

Serving multiple paths, setting the HTTP port via CLI arguments

$ http-file-server -p 1234 /1=/tmp /2=/var/tmp
2018/11/13 23:01:44 serving local path "/tmp" on "/1/"
2018/11/13 23:01:44 serving local path "/var/tmp" on "/2/"
2018/11/13 23:01:44 redirecting to "/1/" from "/"
2018/11/13 23:01:44 http-file-server listening on ":1234"

Setting the HTTP port via environment variables

$ export PORT=9999
$ http-file-server /abc/def/ghi=/tmp
2018/11/13 23:05:52 serving local path "/tmp" on "/abc/def/ghi/"
2018/11/13 23:05:52 redirecting to "/abc/def/ghi/" from "/"
2018/11/13 23:05:52 http-file-server listening on ":9999"

Uploading files using cURL

$ http-file-server -uploads /=/path/to/serve
2020/03/10 22:00:54 serving local path "/path/to/serve" on "/"
2020/03/10 22:00:54 http-file-server listening on ":8080"
curl -LF "[email protected]" localhost:8080/path/to/upload/to

HTTPS (SSL/TLS)

To terminate SSL at the file server, set -ssl-cert (SSL_CERTIFICATE) and -ssl-key (SSL_KEY) to the respective files' paths:

$ ./http-file-server -port 8443 -ssl-cert server.crt -ssl-key server.key
2020/03/10 22:00:54 http-file-server (HTTPS) listening on ":8443"

Custom templates

screenshot

Create a folder and add base.html

Create a subfolder 'errors' and add html files named 'status code': 401.html, 404.html, 500.html...

example templates in /templates/

$ ./http-file-server -t ./templates
2022/12/02 00:27:24 Added custom templates: ./templates

Create new folder

Set -c or --creates The new directory will be created in the current directory with permissions 665

Note: The POST HTML method is used with the URL request argument new

$ ./http-file-server -c ./

Disable show hidden files or dirs

You can disable the display of hidden files or directories using the -nh or --nohidden argument

Note. Does not affect downloading a directory as an archive.

$ ./http-file-server -nh ./                                                                   

Auth

You can set Basic authorization for all routes using --user and --passwd

$ ./http-file-server --user admin --passwd 123456 ./                                         

Auth single route

You can set Basic authorization for a single route using the format user:passwd@/locatin=./local_path

$ ./http-file-server admin:1234@/home=/tmp/home

Note: The --user and --passwd arguments will be ignored.

For example:

$ ./http-file-server --user user1 --passwd 112233 admin:1234@/main=/tmp/home /home=/test2 /shara=/srv/shara

Here, for all routes, except for /main, global authorization will apply (--user (user1) --passwd (112233))

Download selected

You can download selected files or directory in zip or tar.gz archive

  • The POST HTML method is used with a zip or tar.gz URL request argument
  • Payload items value folder or directory name separated by ;
   Url: /home/?zip
   Payload: items=main.go;help;text1.txt;folder01
   Method: Post
   Headers: "Content-Type": "application/x-www-form-urlencoded"

screenshot

Get it

Using go install

go install github.com/noobcode73/http-file-server@latest

After this the executable is installed in go's normal directorys (see go help install for more information)

Use it

GOPATH/http-file-server [OPTIONS] [[ROUTE=]PATH] [[ROUTE=]PATH...]
Usage of http-file-server:
   -a string
        (alias for -addr) (default ":8080")
  -addr string
        address to listen on (environment variable "ADDR") (default ":8080")
  -c    (alias for -creates)
  -creates
        allow creates folder (environment variable "CREATES")
  -d    (alias for -deletes)
  -deletes
        allow deletes (environment variable "DELETES")
  -nh
        (alias for -nohidden)
  -nohidden
    no allow hidden folders or files (environment variable "NO_HIDDEN")
  -p int
     (alias for -port)
  -passwd string
    global password for all routes (without auth) (environment variable "PASSWD").
  -port int
     port to listen on (overrides -addr port) (environment variable "PORT")
  -q (alias for -quiet)
  -quiet
     disable all log output (environment variable "QUIET")
  -r value
     (alias for -route)
  -route value
      a route definition ROUTE=PATH (ROUTE defaults to basename of PATH if omitted)
  -ssl-cert string
      path to SSL server certificate (environment variable "SSL_CERTIFICATE")
  -ssl-key string
     path to SSL private key (environment variable "SSL_KEY")
  -t string
     (alias for -template)
  -templates string
        path to custom Templates folder html.
                base template = base.html, errors template = "status_code".html (401.html, 404.html, etc.).
                (environment variable "TEMPLATES")
  -u    (alias for -uploads)
  -uploads
        allow uploads (environment variable "UPLOADS")
  -user string
        global user name for all routes (without auth) (environment variable "USER").

http-file-server's People

Contributors

sgreben avatar muller2002 avatar noobcode73 avatar codesoap avatar ltagliamonte avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.