项目作者: sgreben

项目描述 :
tiny portable HTTP file server. single binary, no dependencies. linux, osx, windows. #golang
高级语言: Go
项目地址: git://github.com/sgreben/http-file-server.git
创建时间: 2018-11-13T23:25:30Z
项目社区:https://github.com/sgreben/http-file-server

开源协议:

下载


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 as .zip or .tar.gz (generated on-the-fly).

screenshot

Contents

Examples

Serving a path at /

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

Serving $PWD at /

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

Serving multiple paths, setting the HTTP port via CLI arguments

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

Setting the HTTP port via environment variables

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

Uploading files using cURL

  1. $ ./http-file-server -uploads /=/path/to/serve
  2. 2020/03/10 22:00:54 serving local path "/path/to/serve" on "/"
  3. 2020/03/10 22:00:54 http-file-server listening on ":8080"
  1. curl -LF "file=@example.txt" 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:

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

Get it

Using go get

  1. go get -u github.com/sgreben/http-file-server

Pre-built binary

Or download a binary from the releases page, or from the shell:

  1. # Linux
  2. curl -L https://github.com/sgreben/http-file-server/releases/download/1.6.1/http-file-server_1.6.1_linux_x86_64.tar.gz | tar xz
  3. # OS X
  4. curl -L https://github.com/sgreben/http-file-server/releases/download/1.6.1/http-file-server_1.6.1_osx_x86_64.tar.gz | tar xz
  5. # Windows
  6. curl -LO https://github.com/sgreben/http-file-server/releases/download/1.6.1/http-file-server_1.6.1_windows_x86_64.zip
  7. unzip http-file-server_1.6.1_windows_x86_64.zip

Use it

  1. http-file-server [OPTIONS] [[ROUTE=]PATH] [[ROUTE=]PATH...]
  1. Usage of http-file-server:
  2. -a string
  3. (alias for -addr) (default ":8080")
  4. -addr string
  5. address to listen on (environment variable "ADDR") (default ":8080")
  6. -p int
  7. (alias for -port)
  8. -port int
  9. port to listen on (overrides -addr port) (environment variable "PORT")
  10. -q (alias for -quiet)
  11. -quiet
  12. disable all log output (environment variable "QUIET")
  13. -r value
  14. (alias for -route)
  15. -route value
  16. a route definition ROUTE=PATH (ROUTE defaults to basename of PATH if omitted)
  17. -ssl-cert string
  18. path to SSL server certificate (environment variable "SSL_CERTIFICATE")
  19. -ssl-key string
  20. path to SSL private key (environment variable "SSL_KEY")
  21. -u (alias for -uploads)
  22. -uploads
  23. allow uploads (environment variable "UPLOADS")