handle PASV
parent
f1f5ea3a77
commit
c988c67089
|
@ -5,7 +5,7 @@ io.encodings io.encodings.binary io.encodings.utf8 io.files
|
||||||
io.server io.sockets kernel math.parser namespaces sequences
|
io.server io.sockets kernel math.parser namespaces sequences
|
||||||
ftp io.unix.launcher.parser unicode.case splitting assocs
|
ftp io.unix.launcher.parser unicode.case splitting assocs
|
||||||
classes io.server destructors calendar io.timeouts
|
classes io.server destructors calendar io.timeouts
|
||||||
io.streams.duplex threads continuations
|
io.streams.duplex threads continuations math
|
||||||
concurrency.promises byte-arrays ;
|
concurrency.promises byte-arrays ;
|
||||||
IN: ftp.server
|
IN: ftp.server
|
||||||
|
|
||||||
|
@ -78,24 +78,34 @@ C: <ftp-list> ftp-list
|
||||||
|
|
||||||
ERROR: type-error type ;
|
ERROR: type-error type ;
|
||||||
|
|
||||||
: handle-TYPE ( obj -- )
|
: parse-type ( string -- string' )
|
||||||
[
|
>upper {
|
||||||
tokenized>> second >upper {
|
|
||||||
{ "IMAGE" [ "Binary" ] }
|
{ "IMAGE" [ "Binary" ] }
|
||||||
{ "I" [ "Binary" ] }
|
{ "I" [ "Binary" ] }
|
||||||
[ type-error ]
|
[ type-error ]
|
||||||
} case
|
} case ;
|
||||||
|
|
||||||
|
: handle-TYPE ( obj -- )
|
||||||
|
[
|
||||||
|
tokenized>> second parse-type
|
||||||
200 "Switching to " rot " mode" 3append server-response
|
200 "Switching to " rot " mode" 3append server-response
|
||||||
] [
|
] [
|
||||||
2drop "TYPE is binary only" ftp-error
|
2drop "TYPE is binary only" ftp-error
|
||||||
] recover ;
|
] recover ;
|
||||||
|
|
||||||
|
: 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 -- )
|
: handle-PWD ( obj -- )
|
||||||
drop
|
drop
|
||||||
257 current-directory get "\"" swap "\"" 3append server-response ;
|
257 current-directory get "\"" swap "\"" 3append server-response ;
|
||||||
|
|
||||||
: random-local-server ( -- server )
|
: handle-SYST ( obj -- )
|
||||||
remote-address get class new 0 >>port binary <server> ;
|
drop
|
||||||
|
215 "UNIX Type: L8" server-response ;
|
||||||
|
|
||||||
: handle-STOR ( obj -- )
|
: handle-STOR ( obj -- )
|
||||||
[
|
[
|
||||||
|
@ -156,7 +166,7 @@ M: ftp-put service-command ( stream obj -- )
|
||||||
3drop "File transfer failed" ftp-error
|
3drop "File transfer failed" ftp-error
|
||||||
] recover ;
|
] recover ;
|
||||||
|
|
||||||
: extended-passive-loop ( server -- )
|
: passive-loop ( server -- )
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
|dispose
|
|dispose
|
||||||
|
@ -191,16 +201,28 @@ M: ftp-put service-command ( stream obj -- )
|
||||||
[ tokenized>> second <ftp-get> swap fulfill ]
|
[ tokenized>> second <ftp-get> swap fulfill ]
|
||||||
curry if-command-promise ;
|
curry if-command-promise ;
|
||||||
|
|
||||||
|
: expect-connection ( -- port )
|
||||||
|
random-local-server
|
||||||
|
client get <promise> >>command-promise drop
|
||||||
|
[ [ passive-loop ] curry in-thread ]
|
||||||
|
[ addr>> port>> ] bi ;
|
||||||
|
|
||||||
|
: handle-PASV ( obj -- )
|
||||||
|
drop client get passive >>mode drop
|
||||||
|
expect-connection
|
||||||
|
[
|
||||||
|
"Entering Passive Mode (127,0,0,1," %
|
||||||
|
port>bytes [ number>string ] bi@ "," swap 3append %
|
||||||
|
")" %
|
||||||
|
] "" make 227 swap server-response ;
|
||||||
|
|
||||||
: handle-EPSV ( obj -- )
|
: handle-EPSV ( obj -- )
|
||||||
drop
|
drop
|
||||||
client get command-promise>> [
|
client get command-promise>> [
|
||||||
"You already have a passive stream" ftp-error
|
"You already have a passive stream" ftp-error
|
||||||
] [
|
] [
|
||||||
229 "Entering Extended Passive Mode (|||"
|
229 "Entering Extended Passive Mode (|||"
|
||||||
random-local-server
|
expect-connection number>string
|
||||||
client get <promise> >>command-promise drop
|
|
||||||
[ [ B extended-passive-loop ] curry in-thread ]
|
|
||||||
[ addr>> port>> number>string ] bi
|
|
||||||
"|)" 3append server-response
|
"|)" 3append server-response
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
|
@ -241,7 +263,7 @@ ERROR: not-a-directory ;
|
||||||
{ "QUIT" [ handle-QUIT f ] }
|
{ "QUIT" [ handle-QUIT f ] }
|
||||||
|
|
||||||
! { "PORT" [ ] }
|
! { "PORT" [ ] }
|
||||||
! { "PASV" [ ] }
|
{ "PASV" [ handle-PASV t ] }
|
||||||
! { "MODE" [ ] }
|
! { "MODE" [ ] }
|
||||||
{ "TYPE" [ handle-TYPE t ] }
|
{ "TYPE" [ handle-TYPE t ] }
|
||||||
! { "STRU" [ ] }
|
! { "STRU" [ ] }
|
||||||
|
@ -263,7 +285,7 @@ ERROR: not-a-directory ;
|
||||||
{ "PWD" [ handle-PWD t ] }
|
{ "PWD" [ handle-PWD t ] }
|
||||||
! { "ABOR" [ ] }
|
! { "ABOR" [ ] }
|
||||||
|
|
||||||
! { "SYST" [ drop ] }
|
{ "SYST" [ handle-SYST t ] }
|
||||||
! { "STAT" [ ] }
|
! { "STAT" [ ] }
|
||||||
! { "HELP" [ ] }
|
! { "HELP" [ ] }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue