From 8142ffa4d9a22163e82b07dd073c043cf12ed175 Mon Sep 17 00:00:00 2001 From: Eli Barzilay Date: Fri, 5 Aug 2011 01:08:21 -0400 Subject: [PATCH] Return a file size string when possible. This takes the advice from http://files.stairways.com/other/ftp-list-specs-info.txt further: search for the date by an explicit occurrence of a known month name. This means that we won't see files with bad names (they'd be filtered out of the result), but the filtered out entries are ones that would not be usable with `ftp-make-file-seconds'. When the month is found, and the entry is a file, look for a number preceding the month, and if found, return it as the file size string. This is a minor change in the API. (But it's probably better to either revise it further, or eventually make it irrelevant by exposing the interesting functionality via `net/url'.) original commit: 6a1336e75edff75b7fc8a22a31d776acadc536eb --- collects/net/ftp-unit.rkt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/collects/net/ftp-unit.rkt b/collects/net/ftp-unit.rkt index 1f4aa70..7a80f7c 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