 
 ERROR: type-error type ;
 
+: parse-type ( string -- string' )
+    >upper {
+        { "IMAGE" [ "Binary" ] }
+        { "I" [ "Binary" ] }
+        [ type-error ]
+    } case ;
+
 : handle-TYPE ( obj -- )
     [
-        tokenized>> second >upper {
-            { "IMAGE" [ "Binary" ] }
-            { "I" [ "Binary" ] }
-            [ type-error ]
-        } case
+        tokenized>> second parse-type
         200 "Switching to " rot " mode" 3append server-response
     ] [
         2drop "TYPE is binary only" ftp-error
     ] recover ;
-
-: handle-PWD ( obj -- )
-    drop
-    257 current-directory get "\"" swap "\"" 3append server-response ;
 
 : random-local-server ( -- server )
     remote-address get class new 0 >>port binary <server> ;
+
+: port>bytes ( port -- hi lo )
+    [ -8 shift ] keep [ HEX: ff bitand ] bi@ ;
+
+: handle-PWD ( obj -- )
+    drop
+    257 current-directory get "\"" swap "\"" 3append server-response ;
+
+: handle-SYST ( obj -- )
+    drop
+    215 "UNIX Type: L8" server-response ;
 
 : handle-STOR ( obj -- )
     [

io.server io.sockets kernel math.parser namespaces sequences
ftp io.unix.launcher.parser unicode.case splitting assocs
classes io.server destructors calendar io.timeouts
io.streams.duplex threads continuations
concurrency.promises byte-arrays ;
IN: ftp.server


        3drop "File transfer failed" ftp-error
    ] recover ;

: passive-loop ( server -- )
    [
        [
            |dispose
