
suppose i want to write a stupid ftp client, i want to connect to the ftp server, wait for it to give it's intro stuff (welcome to blah, username: ) and then it wants input. how do i do something like this? so far, i have (don't laugh, this is the first socket haskell program i've written. ever.)
connect cfg = withSocketsDo $ do h <- connectTo (remoteAddr cfg) (Service (remoteType cfg)) hWaitForInput h 1000 s <- readWhileAvailable h return s
readWhileAvailable h = do b <- hReady h if b then do c <- hGetChar h s <- readWhileAvailable h return (c : s) else do return []
but this doesn't seem to ever halt :) if i get rid of the hWaitForInput, it returns immediately with nothing. if i replace hWaitForInput...readWhileAvailable with "s <- getContents h ; return (take 10 s)" i get the beginning of the intro message (so it is connecting properly). please someone help me :) -- Hal Daume III "Computer science is no more about computers | hdaume@isi.edu than astronomy is about telescopes." -Dijkstra | www.isi.edu/~hdaume

In local.glasgow-haskell-users, you wrote:
suppose i want to write a stupid ftp client, i want to connect to the ftp server, wait for it to give it's intro stuff (welcome to blah, username: ) and then it wants input. how do i do something like this?
connect cfg = withSocketsDo $ do h <- connectTo (remoteAddr cfg) (Service (remoteType cfg)) hWaitForInput h 1000 s <- readWhileAvailable h return s
Why don't you use hGetLine? FTP is line based, so you just have to loop until there's no dash in the response. -- Wonderful \hbox (0.80312pt too nice) in paragraph at lines 16--18 Volker Stolz * stolz@i2.informatik.rwth-aachen.de Please use PGP or S/MIME for correspondence!
participants (2)
-
Hal Daume III
-
Volker Stolz