ftp/ftp.x
author Madhusudan.C.S <madhusudancs@gmail.com>
Mon, 18 Jan 2010 14:10:13 +0530
changeset 0 30d751ac6d49
child 1 47438813ede2
permissions -rw-r--r--
Solution to first assignment. First assignment was to implement a FTP Server and Client using SUN RPC. This is in C. Doesn't support binary file formats yet. Both binary file format transfer support and Python equivalent of the code is to be added yet.

/*
 * ftp.x: FTP Protocol specification for remote file fetching
 */

const MAXLEN = 1024;

/*
 * Type for storing path
 */
typedef string filename<MAXLEN>;

/*
 * Structure for sending request. Expects the path of the file
 * and the byte number at which to start reading the file from
 */
struct request {
	filename name;
    int start;
};

/*
 * Type that represents the structute for request
 */
typedef struct request request;

/*
 * Type for storing a chunk of the file that is being
 * sent from the server to the client in the current
 * remote procedure call
 */
typedef int filechunk<MAXLEN>;

/*
 * Response sent by the server to the client as a response
 * to remote procedure call, containing the filechunk for
 * the current call and number of bytes actually read
 */
struct chunkreceive {
	filechunk data;
	int bytes;
};

/*
 * Type that represents the structure for file's chunks
 * to be received from the server
 */
typedef struct chunkreceive chunkreceive;

/*
 * File data sent by the server from client to store
 * it on the server along with the filename and the
 * number of bytes in the data
 */
struct chunksend {
	filename name;
    filechunk data;
	int bytes;
};

/*
 * Type that represents the structure for file's chunks
 * to be sent to the server 
 */
typedef struct chunksend chunksend;

/*
 * union for returning from remote procedure call, returns
 * the proper chunkdata response if everything worked fine
 * or will return the error number if an error occured
 */
union readfile_res switch (int errno) {
	case 0:
	    chunkreceive chunk;
	default:
	    void;
};

/*
 * Remote procedure defined in the Interface Definition Language
 * of SUN RPC, contains PROGRAM and VERSION name definitions and
 * the remote procedure signature
 */
program FTPPROG {
	version FTPVER {
		readfile_res retrieve_file(request *) = 1;
		int send_file(chunksend *) = 2;
	} = 1;
} = 0x20000011;