 assocs classes io.servers.connection destructors calendar
 io.timeouts io.streams.duplex threads continuations math
 concurrency.promises byte-arrays io.backend tools.hexdump
-tools.files io.streams.string ;
+tools.files io.streams.string math.bitwise ;
 IN: ftp.server
 
 TUPLE: ftp-client url mode state command-promise user password ;

: handle-TYPE ( obj -- )
    [
        tokenized>> second parse-type
        200 "Switching to " rot " mode" 3append server-response
    ] [
        2drop "TYPE is binary only" ftp-error
    ] recover ;


: handle-PASV ( obj -- )
    drop client get passive >>mode drop
    221
    expect-connection port>bytes [ number>string ] bi@ "," glue
    "Entering Passive Mode (127,0,0,1," ")" surround
    server-response ;

: handle-EPSV ( obj -- )
    drop
    client get command-promise>> [
        "You already have a passive stream" ftp-error
    ] [
        229
        expect-connection number>string
        "Entering Extended Passive Mode (|||" "|)" surround
        server-response
    ] if ;

! LPRT 6,16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,242,186
