Chapter 7

FTP Client

The ftp structure lets you transfer files between networked machines from the Scheme Shell, using the File Transfer Protocol as described in RFC 959.

Some of the procedures in this module extract useful information from the server's reply, such as the size of a file, or the name of the directory we have moved to. These procedures return the extracted information, or, if the server's response doesn't match the expected code from the server, a catchable ftp-error is raised.

(ftp-connect host login password passive? [log-port])     --->     connection         (procedure) 
Open a command connection with the remote machine host and login on that server with login and password. Login and password can be #f, in which case the information is extracted from the user's .netrc file if necessary.

If log-port is specified, it must be an output port: this starts logging the conversation with the server to that port. Note that the log contains passwords in clear text.

(ftp-type <.name.>)     --->     ftp-type         (syntax) 
(set-ftp-type! connection ftp-type)     --->     undefined         (procedure) 
This change the transfer mode for future file transfers. The transfer mode is specfified by ftp-type which can be created with the ftp-type macro. <.Name.> must be either binary for binary data or ascii for text.

(ftp-rename connection old new)     --->     undefined         (procedure) 
This changes the name of old on the remote host to new (assuming sufficient permissions). Old and new are strings.

(ftp-delete connection file)     --->     undefined         (procedure) 
This deletes file from the remote host (assuming the user has appropriate permissions).

(ftp-cd connection dir)     --->     undefined         (procedure) 
This changes the current directory on the server.

(ftp-cdup connection)     --->     undefined         (procedure) 
This move to the parent directory on the server.

(ftp-pwd connection)     --->     string         (procedure) 
Return the current directory on the remote host, as a string.

(ftp-ls connection [dir])     --->     list         (procedure) 
This returns a list of filenames on the remote host, either from the current directory (if dir is not specified), or from the directory specified by dir.

(ftp-dir connection [dir])     --->     status         (procedure) 
This returns a list of long-form file name entries on the remote host, either from the current directory (if dir is not specified), or from the directory specified by dir. (Note that the format for the long-form entries is not specified by the FTP standard.)

(ftp-get connection remote-file proc)     --->     undefined         (procedure) 
This downloads remote-file from the FTP server. Ftp-get establishes a data conneciton to the server, attaches an input port to the data connection, and calls proc on that port.

(ftp-put connection remote-file proc)     --->     undefined         (procedure) 
This uploads remote-file to the FTP server. Ftp-put establishes a data conneciton to the server, attaches an output port to the data connection, and calls proc on that port.

(ftp-append connection remote-file proc)     --->     undefined         (procedure) 
This appends data to remote-file on the FTP server. Ftp-append establishes a data conneciton to the server, attaches an output port to the data connection, and calls proc on that port.

(ftp-rmdir connection dir)     --->     undefined         (procedure) 
This removes the directory dir from the remote host (assuming sufficient permissions).

(ftp-mkdir connection dir)     --->     undefined         (procedure) 
This create a new directory named dir on the remote host (assuming sufficient permissions).

(ftp-modification-time connection file)     --->     date         (procedure) 
This requests the time of the last modification of file on the remote host, and on success return a Scsh date record. (This command is not part of RFC 959 and is not implemented by all servers, but is useful for mirroring.)

(ftp-size connection file)     --->     integer         (procedure) 
This returns the size of file in bytes. (This command is not part of RFC 959 and is not implemented by all servers.)

(ftp-quit connection)     --->     undefined         (procedure) 
This closes the connection to the remote host. The connection object is useless after a quit command.

(ftp-quot connection command)     --->     status         (procedure) 
This sends a command verbatim to the remote server and wait for a response. The response text is returned verbatim.

(ftp-error? thing)     --->     boolean         (procedure) 
This returns #t if thing is a ftp-error object, otherwise #f.

(copy-port->port-binary input-port oputput-port)     --->     undefined         (procedure) 
(copy-port->port-ascii input-port oputput-port)     --->     undefined         (procedure) 
(copy-ascii-port->port input-port oputput-port)     --->     undefined         (procedure) 
These procedures are useful for downloading and uploading data to an FTP connection via ftp-get, ftp-get, and ftp-append. They all copy data from one port to another. Copy-port->port-binary copies verbatim, while the other two perform CR/LF conversion for ASCII data transfers. Copy-port->port-ascii adds CR/LFs at line endings on output, whereas Copy-ascii-port->port removes CR/LFs at line endings end replaces them by ordinary LFs.