FServer is a micro file sharing web server for sharing files and directories on the local network or over the internet. FServer is easier to modify and maintain as it is written in Kotlin.
Features
- Easier usage, not required any system administration or complicated configuration files.
- Single-jar file and zero dependencies.
- Sharing multiple directories
- Serve static web sites or any directory containing an index.html file.
- File upload
- Hide/display pictures
- Optional: session/based and form-based authentication.
- Image thumbnail of PDF files, requires –pdf command line switch. [EXPERIMENTAL]
- Response web page layout which makes it mobile-friendly and usable from tablets and smartphones.
Implementation
- Written in Kotlin for JVM (Java Virtual Machine)
- Build System: Gradle + Gradle-Kotlin DSL
Libraries Used
- Web Framework:
- Command Line:
- Logging:
- Toml configuration file:
- Apache PDFBox library for manipulating and displaying PDF files
- Javascript library for pan, zooming and pinching on mobile/touchscreen devices.
Binary Releases can be download from:
Example: Donwload and running artifact from command line
Download artifact:
$ curl -O -L https://github.com/caiorss/fserver/releases/download/v0.1/fserver.js
$ chmod +x fserver.jsh
Run the server:
- $ ./fserver.jsh [PARAMETERS] …
- $ sh fserver.jsh [PARAMETERS] …
- $ java -jar fserver.jsh [PARAMETERS] …
$ sh ./fserver.jsh
Usage: fserver [OPTIONS] COMMAND [ARGS]...
FServer - micro file sharing server
Options:
-h, --help Show this message and exit
Commands:
dir Serve a single directory
mdir Serve multiple directories
config Start server from user-provided configuration file.
test Run server in demonstration mode.
dummy Dummy command
Share single directory (current directory):
- The site will be available in the URL http://localhost:9042 or
http://<LOCAL_IP_ADDRESS>:9042/
, in this case: http://192.165.15.154:9042.
$ ./fserver.jsh dir ~/Documents --port=9042
[main] INFO io.javalin.Javalin -
__ __ _
/ /____ _ _ __ ____ _ / /(_)____
__ / // __ `/| | / // __ `// // // __ \
/ /_/ // /_/ / | |/ // /_/ // // // / / /
\____/ \__,_/ |___/ \__,_//_//_//_/ /_/
https://javalin.io/documentation
[main] INFO org.eclipse.jetty.util.log - Logging initialized @286ms to org.eclipse.jetty.util.log.Slf4jLog
[main] INFO io.javalin.Javalin - Starting Javalin ...
[INFO] File Web Server URL => http://192.165.15.154:9042
... ... ... ... ...
- Part 1: Start the server.
- –port=9025
- => Server listent to port 9025 (default 9080)
- –upload
- => Enable upload which is disabled by default.
- –auth=myuser:mypass
- => Enable authentication with ‘myuser’ as login and ‘mypass’ as password.
- etc:/etc
- => Shares the directory /etc which is mapped to the URL http://localhost:9025/directory/etc
- downloads:~/Downloads
- => Shares the directory ~/Downloads which is mapped to the URL http://localhost:9025/directory/downloads
- –port=9025
$ java -jar build/libs/fserver-fat.jar mdir --port=9025 \
--upload \
--showpath \
--auth=myuser:mypass \
etc:/etc currentdir:. downloads:~/Downloads
Output:
[main] INFO io.javalin.Javalin -
__ __ _
/ /____ _ _ __ ____ _ / /(_)____
__ / // __ `/| | / // __ `// // // __ \
/ /_/ // /_/ / | |/ // /_/ // // // / / /
\____/ \__,_/ |___/ \__,_//_//_//_/ /_/
https://javalin.io/documentation
[main] INFO org.eclipse.jetty.util.log - Logging initialized @309ms to org.eclipse.jetty.util.log.Slf4jLog
[main] INFO io.javalin.Javalin - Starting Javalin ...
[main] INFO io.javalin.Javalin - Listening on http://localhost:9025/
[main] INFO io.javalin.Javalin - Javalin started in 190ms \o/
[qtp214074868-15] INFO org.eclipse.jetty.util.TypeUtil - JVM Runtime does not support Modules
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
To enable TSL, use command line option –tslcert=<PASSWORD>:<CERTFICATE-FILE>:
- When the TSL is enabled, the URL becomes ‘https’ instead of ‘http’. So the site is also acessible from https://localhost:9025 (Local host).
- The web browser scary warning can be ignored as in this case, the TSL is being used to encrypt the connection over the local network (LAN) or the over the internet.
$ java -jar build/libs/fserver-fat.jar mdir --port=9025 \
--tslcert=mypassword:./cert-test.tsl
--upload \
--showpath \
--auth=myuser:mypass \
etc:/etc currentdir:. downloads:~/Downloads
- Part 2: Browser the URL http://localhost.com:9025 or http://<my_local_ip_address>:9025
Login Page:
Index page: contains the shared directories pages.
Directory listing 1:
Directory listing 2:
Directory listing 3: (Mobile, responsive design mode)
The FServer application can also be initialized from a TOML configuration file, which is a human-readable format.
File: server-conf.toml
[FSERVER]
# Current port that the server will listen to.
port = 9080
# Authentication (Optiona): <USER>:<PASSWORD>
auth = "myuser:mypassword"
# Show/hide path of shared directories in the index page.
showdirectory = false
# Enable/disable upload
upload = true
# Enable PDF Thumbnail [EXPERIMENTAL FEATURE]
pdfthumbnail = true
# Key-value pairs
# <DIRECTORY-LABEL>:<DIRECTORY_PATH>
paths = [
, "desk:~/Desktop"
, "files:~/Downloads/firefox/"
# Static web site html (contains an index.html file)
, "conf:/etc"
]
This configuration:
- Listen incoming http connection at port 9080
- Set authentication: ‘myuser’ as username and ‘mypassword’ as password. This field can be disabled by commenting it.
- Creates the following pages/URLs
- http://localhost:9090/directory/desk => Shows the content of the directory ~/Desktop
- http://localhost:9090/directory/files => Shows the content of the directory ~/Downloads/firefox
- http://localhost:9090/directory/conf => Shows the content of the directory /etc
Running:
- $ java -jar build/libs/fserver-fat.jar config server-conf.toml
$ java -jar build/libs/fserver-fat.jar config server-conf.toml
[INFO] Server listening port: 9080 => URL: http://localhost:9080
[INFO] Server authentication login = user:pass
Shared directories =
=> desk:~/Desktop
=> files:~/Downloads
=> wiki:~/Documents/wiki
=> etc:/etc
------------------------------------------------------------
[main] INFO io.javalin.Javalin -
__ __ _
/ /____ _ _ __ ____ _ / /(_)____
__ / // __ `/| | / // __ `// // // __ \
/ /_/ // /_/ / | |/ // /_/ // // // / / /
\____/ \__,_/ |___/ \__,_//_//_//_/ /_/
https://javalin.io/documentation
[main] INFO org.eclipse.jetty.util.log - Logging initialized @342ms to org.eclipse.jetty.util.log.Slf4jLog
[main] INFO io.javalin.Javalin - Starting Javalin ...
[main] INFO io.javalin.Javalin - Listening on http://localhost:9080/
[main] INFO io.javalin.Javalin - Javalin started in 189ms \o/
[qtp2042495840-16] INFO org.eclipse.jetty.util.TypeUtil - JVM Runtime does not support Modules
STEP 1: Create a self-signed certificate by running the following command and typing ‘yes’ to the final prompt. If there is already an existing one, skip this step. This step generates the certificate file test-cert.jks with password set to ‘mypassword’.
$ keytool -genkey -keyalg RSA -storetype PKCS12 -alias sec_server \
-keystore test-cert.jks \
-storepass mypassword \
-validity 1000000 -keysize 2048
STEP 2: Create the configuration file server-conf.toml with the following content:
File: server-conf.toml
[FSERVER]
# Current port that the server will listen to.
port = 9080
# Authentication (Optiona): <USER>:<PASSWORD>
auth = "myuser:mypassword"
# Show/hide path of shared directories in the index page.
showdirectory = false
# Enable/disable upload
upload = true
# <OPTIONAL> If 'tslcert' variable is set with <PASSWORD>:<CERTIFICATE-FILE>
# it enables SSL/TSL which makes the connection encrypted.
#
# The server URL becomes 'https://<SERVER-ADDR>:<PORT>'
# instead of 'http://<SERVER-ADDR>:<PORT>'
tslcert = "mypassword:./test-cert.jks"
# Key-value pairs
# <DIRECTORY-LABEL>:<DIRECTORY_PATH>
paths = [
, "desk:~/Desktop"
, "files:~/Downloads/firefox/"
# Static web site html (contains an index.html file)
, "conf:/etc"
]
STEP 3: Run server. When SSL/TSL is enabled, the server URL becomes https://server-address:9080 or https://localhost:9080 when accessing from local host.
$ java -jar build/libs/fserver-fat.jar config config.toml
Note: The compilation requires a gradle and Kotlin installation:
Build
$ gradle build
Test
- $ java -jar build/libs/fserver-fat.jar
$ java -jar build/libs/fserver-fat.jar
Usage: commandmain [OPTIONS] COMMAND [ARGS]...
Options:
-h, --help Show this message and exit
Commands:
dir Serve a single directory
mdir Serve multiple directories
config Start server from user-provided configuration file.
test Run server in demonstration mode.
dummy Dummy command
Show help for all commands
$ java -jar build/libs/fserver-fat.jar Usage: fserver [OPTIONS] COMMAND [ARGS]... FServer - micro file sharing server Options: -h, --help Show this message and exit Commands: dir Serve a single directory mdir Serve multiple directories config Start server from user-provided configuration file. test Run server in demonstration mode. dummy Dummy command
Show help for the command ‘dir’
- $ java -jar build/libs/fserver-fat.jar dir –help
$ java -jar build/libs/fserver-fat.jar dir -h
Usage: fserver dir [OPTIONS] PATH
Serve a single directory
Options:
--port INT Http Server port (default 9080)
--auth TEXT Enable Authentication. <USERNAME>:<PASSWORD>
--upload Enable upload
--showpath Show absolute paths of shared directories
--pdf Render thumbnails of PDF files of listed directories
-h, --help Show this message and exit
Arguments:
PATH Directory to be served
Show help for the command mdir
$ java -jar build/libs/fserver-fat.jar mdir -h
Usage: fserver mdir [OPTIONS] [PATHLIST]...
Serve multiple directories
Options:
--port INT Http Server port (default 9080)
--auth TEXT Enable Authentication. <USERNAME>:<PASSWORD>
--upload Enable upload
--showpath Show absolute paths of shared directories
--pdf Render thumbnails of PDF files of listed directories
--tslcert TEXT TSL/SSL Certificate and passwrod <PASSWORD>:<FILE>
-h, --help Show this message and exit
Arguments:
PATHLIST Directories => <label>:<directory> to be served