Note: This is taken from the Chicken Wiki, where a more recent version could be available.
A simple FTP client library.
Errors triggered by invalid or negative replies from the FTP server are signalled by raising a compund condition of the kinds exn and ftp. The error code of a ftp condition can be accessed with the code property.
<procedure>(ftp:connect HOSTNAME USERNAME PASSWORD [VERBOSE [PORT]])</procedure>
Connects to the server HOSTNAME using the FTP protocol and identifies this client with USERNAME with a given PASSWORD (all strings). If the optional argument VERBOSE is given and not #f, then a protocol of the communication with the server is written to the value of (current-error-port). PORT specifies the port-number and defaults to 21.
This procedure returns an object representing the FTP session.
Closes the connection identified by the session object FTP.
Returns #t if X is an FTP session object, or #f otherwise.
<procedure>(ftp:set-type! FTP TYPE)</procedure>
Sets the transmission to binary or character type. TYPE should one of the symbols binary, image or ascii.
<procedure>(ftp:set-mode! FTP MODE)</procedure>
Selects active or passive mode. MODE should one of the symbols active or passive. Passive mode is the default.
<procedure>(ftp:change-directory FTP DIR)</procedure>
Changes the current directory of the FTP session FTP to DIR.
<procedure>(ftp:open-list FTP [MASK [LONG]])</procedure>
Returns an input-port from which a directory list can be retrieved. The optional string MASK selects files to be listed (like *.scm). If the optional flag LONG is given and not #f, then the directory is requested in "long" format (if the server differentiates between short and long directory format). After the directory has been read, the port must be closed to allow further read/write operations in this FTP session.
<procedure>(ftp:open-input-file FTP FILENAME)</procedure>
Opens the file FILENAME for retrieval from the FTP server and returns an input-port from which the file can be read. After the file has been read, the port must be closed to allow further read/write operations in this FTP session.
<procedure>(ftp:open-output-file FTP FILENAME)</procedure>
Opens the file FILENAME the FTP server and returns an output-port to which the data to be stored should be written. After the file has been written, the port must be closed to allow further read/write operations in this FTP session.
Aborts any transmission currently in progress for the given FTP session.
<procedure>(ftp:delete-file FTP FILENAME)</procedure>
Deletes the file FILENAME on the FTP server.
<procedure>(ftp:rename-file FTP OLD NEW)</procedure>
Renames the file OLD on the FTP server to NEW.
<procedure>(ftp:delete-directory FTP DIRNAME)</procedure>
Deletes the directory DIRNAME on the FTP server.
<procedure>(ftp:create-directory FTP DIRNAME)</procedure>
Creates the directory DIRNAME on the FTP server.
<example> <expr> ; Connect to FTP server: (define f (ftp:connect "ftp.foo.com" "joe" "secret"))
(let ([p (ftp:open-list f)])
(display (read-string #f p)) (close-input-port p) )
(lambda () (let ([p (ftp:open-input-file f "foo.txt")]) (display (read-string #f p)) (close-input-port p) ) ) )
(ftp:disconnect f) </expr> </example>
Copyright (c) 2003, Felix L. Winkelmann All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.