 unicode.case splitting assocs classes io.servers.connection
 destructors calendar io.timeouts io.streams.duplex threads
 continuations math concurrency.promises byte-arrays
-io.backend sequences.lib tools.hexdump io.files.listing ;
+io.backend sequences.lib tools.hexdump io.files.listing
+io.streams.string ;
 IN: ftp.server
 
-TUPLE: ftp-client url mode state command-promise ;
+TUPLE: ftp-client url mode state command-promise user password ;
 
 : <ftp-client> ( url -- ftp-client )
     ftp-client new


: handle-USER ( ftp-command -- )
    [
        drop
        331 "Please specify the password." server-response
    ] [
        2drop "bad USER" ftp-error

    150 "Here comes the directory listing." server-response ;

: finish-directory ( -- )
    226 "Directory send OK." server-response ;

GENERIC: service-command ( stream obj -- )

M: ftp-list service-command ( stream obj -- )
    drop
    start-directory [
        utf8 encode-output
        [ current-directory get directory. ] with-string-writer string-lines
        harvest [ ftp-send ] each
    ] with-output-stream
    finish-directory ;

