From 6c45ead58b26f9fecfd09ea287d3b73c46af7d75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20G=C3=B3mez?= Date: Thu, 22 Jul 2021 15:56:06 -0230 Subject: [PATCH] Add support for optional port --- README.md | 4 ++++ deps.edn | 6 +++++- src/jgomo3/ftp_hog.clj | 34 +++++++++++++++++++++++++--------- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 87ee003..23caba6 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,10 @@ Then, from an FTP client you can connect to the server on port 2221: ------ 3 user group 0 Jul 13 12:16 text.tmp +You can specify the port with the `:port` option: + + $ clojure -X:run-x :port 2222 + ## License Copyright © 2021 Jesús Gómez (jgomo3) diff --git a/deps.edn b/deps.edn index 415c11f..51cf693 100644 --- a/deps.edn +++ b/deps.edn @@ -8,7 +8,11 @@ :aliases {:run-m {:main-opts ["-m" "jgomo3.ftp-hog"]} :run-x {:ns-default jgomo3.ftp-hog - :exec-fn run} + :exec-fn run + :exec-args {:port 2221 + :path "/tmp" + :user "anonymous" + :password ""}} :test {:extra-paths ["test"] :extra-deps {org.clojure/test.check {:mvn/version "1.1.0"} io.github.cognitect-labs/test-runner diff --git a/src/jgomo3/ftp_hog.clj b/src/jgomo3/ftp_hog.clj index edc5eb5..3f05292 100644 --- a/src/jgomo3/ftp_hog.clj +++ b/src/jgomo3/ftp_hog.clj @@ -1,5 +1,6 @@ (ns jgomo3.ftp-hog - (:require [clojure.java.io :as io]) + (:require [clojure.java.io :as io] + [clojure.string :as str]) (:import [org.apache.ftpserver FtpServer FtpServerFactory] [org.apache.ftpserver.listener ListenerFactory] [org.apache.ftpserver.usermanager PropertiesUserManagerFactory])) @@ -20,12 +21,27 @@ (.setFile file)) (.createUserManager))) +(defn welcome [{:keys [port path user password] :as opts}] + (let [msj-lines ["ftp-hog: Super simple ftp server so you can code." + "" + "This server is serving a non isolated folder." + "The only security are the limitiations the user you used" + "to execute this process has." + "Keep that in mind!" + "" + (str "Currently listening on port " port) + (str "And serving the path " path) + ""] + msj (str/join "\n" msj-lines)] + (println msj))) -(defn run [opts] - (let [user-manager (-> "conf/users.properties" - io/resource - io/file - create-user-manager) - listener (create-listener 2221) - server (create-server listener user-manager)] - (.start server))) +(defn run [{:keys [port path user password] :as opts}] + (do + (welcome opts) + (let [user-manager (-> "conf/users.properties" + io/resource + io/file + create-user-manager) + listener (create-listener port) + server (create-server listener user-manager)] + (.start server))))