From f0448cb34f657b5d374d22f4cbf3d9bf471bafac Mon Sep 17 00:00:00 2001 From: sperber Date: Thu, 16 Jan 2003 10:21:59 +0000 Subject: [PATCH] Have FTP-LS and FTP-DIR returns list of directory lines rather than printing the directory to (current-output-port). --- scheme/lib/ftp.scm | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/scheme/lib/ftp.scm b/scheme/lib/ftp.scm index 8abe4e9..928db66 100644 --- a/scheme/lib/ftp.scm +++ b/scheme/lib/ftp.scm @@ -245,10 +245,11 @@ (code-with-prefix "1")) (receive (newsock newsockaddr) (accept-connection sock) - (dump (socket:inport newsock)) - (close-socket newsock) - (close-socket sock) - (ftp-read-reply connection)))) + (let ((lines (port->lines (socket:inport newsock)))) + (close-socket newsock) + (close-socket sock) + (ftp-read-reply connection) + lines)))) ;;: connection [ x string ] -> status (define (ftp-dir connection . maybe-dir) @@ -258,10 +259,18 @@ (code-with-prefix "1")) (receive (newsock newsockaddr) (accept-connection sock) - (dump (socket:inport newsock)) - (close-socket newsock) - (close-socket sock) - (ftp-read-reply connection)))) + (let ((lines (port->lines (socket:inport newsock)))) + (close-socket newsock) + (close-socket sock) + (ftp-read-reply connection) + lines)))) + +(define (port->lines port) + (let loop ((reverse-lines '())) + (let ((line (rread-crlf-line port))) + (if (eof-object? line) + (reverse reverse-lines) + (loop (cons line reverse-lines)))))) ;; maybe-local may be a filename to which the data should be written,