[plt-scheme] ftp
The code in net/ftp uses the old protocol for open-output-file:
(define (ftp-download-file tcp-ports folder filename)
;; Save the file under the name tmp.file, rename it once download is
;; complete this assures we don't over write any existing file
without
;; having a good file down
(let* ([tmpfile (make-temporary-file
(string-append
(regexp-replace
#rx"~"
(path->string (build-path folder "ftptmp"))
"~~")
"~a"))]
[new-file (open-output-file tmpfile 'replace)]
;; You want #:exists 'replace instead of just 'replace
;; (If I had time and knew where the test suites were, I'd push out a
fix for you.)
[tcpstring (bytes-append #"RETR "
(string->bytes/locale filename)
#"\n")]
[tcp-data (establish-data-connection tcp-ports)])
(display tcpstring (ftp-connection-out tcp-ports))
(ftp-check-response (ftp-connection-in tcp-ports)
(ftp-connection-out tcp-ports)
#"150" print-msg (void))
(copy-port tcp-data new-file)
(close-output-port new-file)
(close-input-port tcp-data)
(ftp-check-response (ftp-connection-in tcp-ports)
(ftp-connection-out tcp-ports)
#"226" print-msg (void))
(rename-file-or-directory tmpfile (build-path folder filename)
#t)))
On May 24, 2010, at 11:01 AM, geb a wrote:
> Can anyone point out what I'm doing wrong with this code? I'm
> having trouble figuring out what the problem is. Thanks for your
> help!
>
> Sincerely,
>
> Dan
>
>
> #lang scheme
> (require net/ftp)
> (define myftp (ftp-establish-connection "10.1.4.157" 21 "anonymous"
> ""))
> (ftp-cd myftp "pub")
> (ftp-directory-list myftp)
>
> (ftp-download-file myftp "/home/dvisher" "mypic.png" )
> (ftp-close-connection myftp)
>
> ;procedure open-output-file: expects 1 argument plus optional
> arguments with keywords #:exists and #:mode, given 2: "/home/dvisher/
> ftptmp1274590128-1015158141" replace
>
>
>
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme