Skip to content

Commit

Permalink
Add support for optional port
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesús Gómez committed Jul 22, 2021
1 parent 8d48e52 commit 6c45ead
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 25 additions & 9 deletions src/jgomo3/ftp_hog.clj
Original file line number Diff line number Diff line change
@@ -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]))
Expand All @@ -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))))

0 comments on commit 6c45ead

Please sign in to comment.