diff --git a/collects/net/ftp-unit.rkt b/collects/net/ftp-unit.rkt index 1f4aa70116..7a80f7c505 100644 --- a/collects/net/ftp-unit.rkt +++ b/collects/net/ftp-unit.rkt @@ -159,7 +159,9 @@ #"250" void (void))) (define re:dir-line - #rx"^(.)......... .* ([A-Z].* .* [0-9][0-9]:?[0-9][0-9]) (.*)$") + (regexp (string-append + "^(.)(.*) ((?i:jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)" + " .* [0-9][0-9]:?[0-9][0-9]) (.*)$"))) (define (ftp-directory-list tcp-ports) (define tcp-data (establish-data-connection tcp-ports)) @@ -173,9 +175,15 @@ (ftp-connection-out tcp-ports) #"226" print-msg (void)) (for*/list ([l (in-list lines)] - [m (in-value (regexp-match re:dir-line l))] + [m (in-value (cond [(regexp-match re:dir-line l) => cdr] + [else #f]))] #:when m) - (cdr m))) + (define size (cond [(and (equal? "-" (car m)) + (regexp-match #rx"([0-9]+) *$" (cadr m))) + => cadr] + [else #f])) + (define r `(,(car m) ,@(cddr m))) + (if size `(,@r ,size) r))) (define (ftp-download-file tcp-ports folder filename) ;; Save the file under the name tmp.file, rename it once download is diff --git a/collects/net/scribblings/ftp.scrbl b/collects/net/scribblings/ftp.scrbl index 9f76d73121..52901c51ac 100644 --- a/collects/net/scribblings/ftp.scrbl +++ b/collects/net/scribblings/ftp.scrbl @@ -46,13 +46,16 @@ Returns a list of files and directories in the current directory of the server, assuming that the server provides directory information in the quasi-standard Unix format. -Each file or directory is represented by a list of three strings. The -first string is either @racket["-"], @racket["d"], or @racket["l"], -depending on whether the items is a file, directory, or link, -respectively. The second item is the file's date; to convert this +Each file or directory is represented by a list of three or four +strings. The first string is either @racket["-"], @racket["d"], or +@racket["l"], depending on whether the items is a file, directory, or +link, respectively. The second item is the file's date; to convert this value to seconds consistent with @racket[file-seconds], pass the date -string to @racket[ftp-make-file-seconds], below. The third string is -the name of the file or directory. +string to @racket[ftp-make-file-seconds]. The third string is the name +of the file or directory. If the item is a file (the first string is +@racket["-"]), and if the line that the server replied with has a size +in the expected place, then a fourth string containing this size is +included. Warning: the FTP protocol has no specification for the reply format, so this information can be unreliable.}