Make `ftp-make-file-seconds' use a correct year instead of 2002.
This function was using 2002 when there's no year... Updated it to use the last occurrence of the guessed date, as described at http://files.stairways.com/other/ftp-list-specs-info.txt This function still looks pretty bogus -- the RFC does *not* say anything about the format of response to `LIST', so it's whatever semi-random thing the server does. (The above link looks like an attempt to fix it, but I didn't see anything more official than that.) From some looking around, it looks like ftp clients just try a bunch of patterns against the text. Add also warnings in the documentation about this.
This commit is contained in:
parent
99d48abcf3
commit
234015b34d
|
@ -11,8 +11,6 @@
|
|||
;; opqaue record to represent an FTP connection:
|
||||
(define-struct ftp-connection (in out))
|
||||
|
||||
(define tzoffset (date-time-zone-offset (seconds->date (current-seconds))))
|
||||
|
||||
(define re:multi-response-start #rx#"^[0-9][0-9][0-9]-")
|
||||
(define re:response-end #rx#"^[0-9][0-9][0-9] ")
|
||||
|
||||
|
@ -75,21 +73,24 @@
|
|||
(define re:date #rx#"(...) *(.*) (..):(..)|(...) *([0-9]*) +(....)")
|
||||
|
||||
(define (ftp-make-file-seconds ftp-date-str)
|
||||
(let ([date-list (regexp-match re:date (string->bytes/utf-8 ftp-date-str))])
|
||||
(if (not (list-ref date-list 4))
|
||||
(find-seconds 0
|
||||
0
|
||||
2
|
||||
(bytes->number (list-ref date-list 6))
|
||||
(get-month (list-ref date-list 5))
|
||||
(bytes->number (list-ref date-list 7)))
|
||||
(+ (find-seconds 0
|
||||
(bytes->number (list-ref date-list 4))
|
||||
(bytes->number (list-ref date-list 3))
|
||||
(bytes->number (list-ref date-list 2))
|
||||
(get-month (list-ref date-list 1))
|
||||
2002)
|
||||
tzoffset))))
|
||||
(define date-list (regexp-match re:date (string->bytes/utf-8 ftp-date-str)))
|
||||
(if (not (list-ref date-list 4))
|
||||
(find-seconds 0 0 0
|
||||
(bytes->number (list-ref date-list 6))
|
||||
(get-month (list-ref date-list 5))
|
||||
(bytes->number (list-ref date-list 7)))
|
||||
(let* ([cur-secs (current-seconds)]
|
||||
[cur-date (seconds->date cur-secs)]
|
||||
[cur-year (date-year cur-date)]
|
||||
[tzofs (date-time-zone-offset cur-date)]
|
||||
[minute (bytes->number (list-ref date-list 4))]
|
||||
[hour (bytes->number (list-ref date-list 3))]
|
||||
[day (bytes->number (list-ref date-list 2))]
|
||||
[month (get-month (list-ref date-list 1))]
|
||||
[guess (+ (find-seconds 0 minute hour day month cur-year) tzofs)])
|
||||
(if (guess . <= . cur-secs)
|
||||
guess
|
||||
(+ (find-seconds 0 minute hour day month (sub1 cur-year)) tzofs)))))
|
||||
|
||||
(define re:passive #rx#"\\((.*),(.*),(.*),(.*),(.*),(.*)\\)")
|
||||
|
||||
|
|
|
@ -52,14 +52,20 @@ 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.}
|
||||
the name of the file or directory.
|
||||
|
||||
Warning: the FTP protocol has no specification for the reply format, so
|
||||
this information can be unreliable.}
|
||||
|
||||
|
||||
@defproc[(ftp-make-file-seconds [ftp-date string?]) exact-integer?]{
|
||||
|
||||
Takes a date string produced by @racket[ftp-directory-list] and
|
||||
converts it to seconds (which can be used with
|
||||
@racket[seconds->date]).}
|
||||
@racket[seconds->date]).
|
||||
|
||||
Warning: the FTP protocol has no specification for the reply format, so
|
||||
this information can be unreliable.}
|
||||
|
||||
|
||||
@defproc[(ftp-download-file [ftp-conn ftp-connection?]
|
||||
|
|
Loading…
Reference in New Issue
Block a user