Project 3 - Mirroring with SFTP

Client-Server Interfaces, Spring 2002


Table of Contents

Due Date

Part 1 of this assignment is due on Wednesday, 17 April, no later than 2:00 p.m. Part 2 of this assignment is due on Friday, 3 May no later than 2:00 p.m.

See the assignment turn-in page (last modified on 4 March 2002) for instructions on turning in your assignment.

Part 1 - Simple FTP

SFTP is a simple file transfer protocol. The version described here is based on the original version described in rfc 913.

SFTP provides a client-server interface to a set of files on a computing system. The SFTP server is responsible for saving and distributing the files. The SFTP clients connect to various SFTP servers and copy files to and from them.

The SFTP Directory

Each SFTP server implements its own directory; only files stored in the SFTP-server directory are accessable to clients. The SFTP-server directory has the standard UNIX directory syntax and (for the most part) semantics; in particular, the top of the directory is known as / (root).

The SFTP API

The error value returned by all sftp commands is the equivalent of the structure

struct status {
  bool error;
  string response;
  };

If error is true, then something bad happend at the sftp server while trying so execute a command; if error is false, then the command was carried out correctly.

The contents of response depends on the command given and whetehr or not it was successful. If error is false, response generally will contain a descriptive error message.

All the SFTP API procedures return status; this return value is omitted from the descriptions that follow.

sftp::cdir(const char * new-directory)

Change a session's current working directory on the sftp server to the argument passed.

sftp::connect(const char * remote-host, const char * session-id)

Start a session with the specified sftp server. The format of the sftp-server name is hostname:port-number. The client may have any number of sessions started , but each session must have a session id unique among all sessions for the client.

A client cannot specify any other commands in a session until the sftp server sends a positive response to a connect command for the session.

sftp::delete(const char * file-spec)

Delete the specified file or directory from the sftp server. Directories must be empty before they can be deleted; only the specified file or directory is deleted.

sftp::disconnect(void)

Ends the session. A client cannot issue any commands from a session that has been disconnected.

sftp::get(bool append,
	  const char * local-file-spec,
	  const char * remote-file-spec)

Copies the contents of the of the specified remote file to the the specified local file. If append is true, the contents are appended to the end of the existing contents of the local file, if any; otherwise, the contents replaces any existing contents. The local file and any parent directories are created if necessary.

File contents are transmitted as a sequence of 8-bit bytes.

sftp::list(bool verbose, const char * directory-path)

Return a list of the files contained in the specified directory path. If verbose is false, the response is a list of file names, each file name separated from the next by a newline character. If verbose is true, the response consists of the name, last modification date in eastern standard time and size in bytes, each entry separated from the next by a newline character.

sftp::put(bool append, 
          const char * remote-file-spec, 
	  const char * local-file-spec)

Copies the contents of the of the specified local file to the the specified remote file. If append is true, the contents are appended to the end of the existing contents of the remote file, if any; otherwise, the contents replaces any existing contents. The remote file and any parent directories are created if necessary.

File contents are transmitted as a sequence of 8-bit bytes.

sftp::rename(const char * old-file-spec, 
             const char * new-file-spec)

Renames the old-file-spec to be new-file-spec on the sftp server.

Part 2 - SFTP Mirroring

For the second part of your project, you will use the SFTP API you implemented in the first part to build a file-mirroring tool that can be used to keep a set of SFTP directories in sync.

A set of SFTP directories are in sync when all directories in the set have the same files, and they all have the most recent version of each file. Keeping a set of SFTP directories in sync essentially involves making sure the most recent version of each file in the set can be found on every directory in the set.

You should build a single tool called sftp-mirror having the command-line format

sftp-mirror sftp-directory sftp-directory...

The form of a sftp-directory is

directory-path@hostname:port

For example, the command

sftp-mirror /cs-538/p3@clsab18:1942 \
  /projects/sftp@rockhopper.monmouth.edu:2001 \
  /538-projects/3-current@AddisAbaba:21012

would sync the SFTP directories /cs-538/p3, /projects/sftp, and /538-projects/3-current.

Implementation Details

Your implementation should include both the client-side routines described above and the server-side CGI programs needed to implement the SFTP server. You must use HTTP as the SFTP transport layer; your client-server communication techniques are restricted to the four transfer mechanisms we covered in class:

  1. Get

  2. Post

  3. Content-Type headers

  4. Other headers

You can use these four mechanisms however you like (assuming it doesn't choke the HTTP server or CGI programs).

You may implement the client and server side using whatever languages and techniques you feel best, as long as they are or can be easily installed on Unix. If you're not going to use C or C++ you should let me know as soon as you can so I can figure out how to deal with it and let you know if it's acceptable.

There's a simple, CGI-capable server available in /export/home/class/cs-537/p3/thttpd. You are not required to use it, but it's the server I'll be using to test your code. See the thttpd page for some information about running thttpd.

It's not an absolute requirement that you solve the server side of this problem using CGI; however, if you want to use something else we'll have to talk about it first.


This page last modified on 3 May 2002.