SimpleSwiftServer
Quick and easy file sharing (direct download or directory browsing) and more.
Why is it better than Python’s SimpleHttpServer?
- Quicker to type: server vs python3 -m http.server or python -m SimpleHTTPServer.
- Supports additional modes beyond directory browsing.
- Allows you to host from a directory that is not your current working directory.
- You don’t have to remember
HTTP
vsHttp
(better in Python 3) - No need to remember how to run the Python http module.
-m http
?-m http.server
?-m SimpleHTTPServer
? Which one goes with which version of Python?
New Use the --debug
flag to log all incoming requests.
Install
Requirements
SimpleSwiftServer does not come pre-compiled, so you’ll need Swift 5.0 or later in order to build it. (This version of Swift comes with Xcode 10.2 or later).
To download Xcode, get it from the Mac App Store or download it from the Apple Developer portal (requires sign-in).
Alternatively, download Swift from Swift.org, using Homebrew, swiftenv, or via some other method.
Homebrew
Installation:
$ brew install Samasaur1/core/simpleswiftserver
Updating:
$ brew upgrade simpleswiftserver
Mint
Installation:
$ mint install Samasaur1/SimpleSwiftServer
Updating:
$ mint install SimpleSwiftServer
Manual Install
Installation & updating:
$ git clone https://github.com/Samasaur1/SimpleSwiftServer.git
$ cd SimpleSwiftServer
$ swift build -c release
$ sudo mv .build/release/server /usr/local/bin/server
Build and run directly:
$ git clone https://github.com/Samasaur1/SimpleSwiftServer.git
$ cd SimpleSwiftServer
$ swift run server git
Usage
SimpleSwiftServer has four modes: a file downloader and a directory browser, to easily share files, a single-HTML-file host mode, and a website directory host mode. It also allows you to specify your port.
Here’s the help information:
$ server --help
OVERVIEW: Host a little server.
This command lets you host multiple different types of servers on your local
machine, accessible to anyone on the network.
USAGE: server [--port <port>] [--browse] [--file] [--webserver] [--html] [<path>] [--debug]
ARGUMENTS:
<path> The path to the file/directory (default: .)
OPTIONS:
--port <port> The port for the server to run on (default: 1234)
--browse/--file/--webserver/--html
The server mode (default: directoryBrowser)
--debug Whether or not to log incoming requests
--version Show the version.
-h, --help Show help information.
As you can see, the default port is 1234, the default mode is a directory browser, and the default path is the current directory.
Examples
Opens a directory browser from the current directory on port 1234
$ server
Opens a directory browser from the current directory on port 4321
$ server --port 4321
Opens a directory browser from the Desktop
subdirectory on port 1234
$ server --browse Desktop
Opens a file downloader for the file Package.swift
in the Desktop subdirectory on port 1234
$ server --file Desktop/Package.swift
Opens a directory browser from the root directory on port 46264. Warning: this is a terrible idea, as any confidential files (tokens, keys) are publically accessible. Share the smallest amount of your system that you need.
$ server --port 46264 --browse /
One full example, with expected output, for serving an HTML file called index.html in the enclosing directory, on port 1337.
[sam](~/Desktop/samasaur1.github.io/projects)$ server --html ../index.html --port 1337 Server has started on port 1337. Try to connect now... Others can do so by going to "10.0.1.83:1337" in a browser ^C [sam](~/Desktop/samasaur1.github.io/projects)$
Notes:
- SimpleSwiftServer has plans for more modes to come (chat). Create an issue to request another mode.
SimpleSwiftServer does not output received requests. This isn’t a bug — it was a deliberate decision — but there’s an issue open to add a--debug
flag to log some of this information. If you’d like that, please say so.- This was resolved in version 4.2.0
- Visit the issues page to see the status of these issues.
Uninstall
SimpleSwiftServer doesn’t leave anything behind, so you can use the normal uninstall method:
$ brew uninstall simpleswiftserver
$ mint uninstall SimpleSwiftServer
$ sudo rm /usr/local/bin/server