Created
October 5, 2016 12:10
-
-
Save Lifelovinglight/49a26d0db9474086896e802615bae45c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun parse-ftp-traffic (str) | |
(case (parse-integer str :junk-allowed t) | |
((220) 'helo) | |
((230) 'login-successful) | |
((331) 'password-requested) | |
((332) 'no-anonymous-logins) | |
((530) 'login-failed) | |
(otherwise nil))) | |
(defun speak (str) | |
(sb-ext:run-program "/usr/bin/espeak" (list "-v" "en+f5" str))) | |
(defmacro ftp-state-function (socket message &body cases) | |
`(progn | |
(if ,message | |
(send-line ,socket ,message)) | |
(case (parse-ftp-traffic (socket-read ,socket)) | |
,@cases | |
(otherwise nil)))) | |
(defun anonymous-ftp-p (name) | |
(handler-case | |
(with-timeout 5 | |
(let ((socket (connect name 21))) | |
(if socket | |
(labels ((listen-for-helo () | |
(ftp-state-function | |
socket nil | |
((helo) (send-username)))) | |
(send-username () | |
(ftp-state-function | |
socket | |
"USER anonymous" | |
((password-requested) (send-password)) | |
((login-successful) t) | |
((no-anonymous-logins) nil))) | |
(send-password () | |
(ftp-state-function | |
socket | |
(concatenate 'string "PASS anonymous@" | |
(format nil "~a" name)) | |
((login-successful) t) | |
((login-failed) nil)))) | |
(prog1 (listen-for-helo) | |
(sb-bsd-sockets:socket-close socket)))))) | |
(sb-ext:timeout (ex) | |
nil))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment