Homework 2
Due Wednesday, April 21
In this problem, you will write a pair of programs, named dtp and dtpd , corresponding to ftp and ftpd.
The program dtp will fetch an entire directory tree which is rooted at the directory specified on the user's command line. (Note: The full path must be specified in that command-line argument, not just a relative path.) The program dtp will copy all files and directories in the entire directory tree, i.e. including subdirectories, subsubdirectories, and so on, and will set up the same tree, rooted in the directory from which dtp is invoked. (The action in terms of directory trees will be similar to cp -r .)
The form of the command line will be
dtp
For example, suppose dtpd is running on sgi8. Then on my machine, heather.cs.ucdavis.edu, I might type
dtp sgi8.cs.ucdavis.edu /home/matloff/Pub/Architecture
to copy the given directory tree from sgi8 to heather. Suppose that when I ran dtp, I was in the directory /uvw/ijk on heather. Then the result would be a new directory /uvw/ijk/home/matloff/Pub/Architecture on heather, containing copies of the files in the corresponding directory tree at sgi8.
The program dtpd is intended to run constantly on machines which offer dtp access. In order to make sure you have tested your code well, run dtp on one architecture, say an SGI, and run dtpd on another, say an HP; better yet, run one of those two programs on a CSIF machine and the other on an ACS machine. (Avoid the DECs, which do not handle this properly.)
The dtpd program does not need to handle more than one request at a time. Do not worry about the file permissions in the files created on the client side.
The dtpd program must also keep a record, in a file named Visitors, of all machines from which it receives dtp "calls". So, in the example above, one of the entries in the Visitor file will be
heather.cs.ucdavis.edu
You may find it helpful to write your code in such a way that each time dtpd writes to the socket connected to dtp , dtpd prefaces the message with an integer indicating the length of the message. That way you can write code for dtp which easily distinguishes where one message ends and another begins. Note: In order to avoid "big/little endian" inconsistency problems between the server and client machines, do not send the integer in raw (binary) form, but use sprintf() instead. (Then use sscanf() to convert back on the client end.)
I recommend that you start with the simpler case first, in which only one level of directory depth is allowed. Once you get that working, then add the recursive feature to implement the general case.
As in all assignments, you must follow specified requirements EXACTLY. In particular, the following are REQUIRED:
In this and all other homework assignments, "must" means "must"; "required" means "required". So for example, you cannot use the tar command to package a directory; that would be inconsistent with the requirements given above. Homework that does not comply with the requirements will not receive credit.
You may find that your programs dtp and dtpd work on "smaller" problems but not on larger ones, say directory trees with a large number of levels, due to your exceeding your limit of file descriptors. If this happens, don't worry about it. (But if you wish to increase the maximum number of file descriptors you are allowed, use the Unix limit command.) Also, if you wish to limit your program to files containing at most, say, 1000 bytes, that is fine.