This project implements a distributed file system using socket programming in C. The system is designed to handle multiple clients and includes three servers: Smain, Spdf, and Stext. Clients interact exclusively with the Smain server, which handles file storage and distribution transparently by delegating certain files to the Spdf and Stext servers.
-
Smain (Main Server):
- Stores
.c
files locally. - Transfers
.pdf
files to the Spdf server. - Transfers
.txt
files to the Stext server.
- Stores
-
Spdf (PDF Server):
- Stores
.pdf
files.
- Stores
-
Stext (Text Server):
- Stores
.txt
files.
- Stores
-
client24s (Client):
- Provides a command-line interface for interacting with the Smain server.
- Smain.c: Contains the implementation for the Smain server.
- Spdf.c: Contains the implementation for the Spdf server.
- Stext.c: Contains the implementation for the Stext server.
- client24s.c: Contains the implementation for the client program.
-
Smain:
- Listens for client connections.
- Manages file storage and redirection of
.pdf
and.txt
files. - Forks a child process for each client connection to handle requests.
-
Spdf:
- Handles requests from Smain for storing and retrieving
.pdf
files.
- Handles requests from Smain for storing and retrieving
-
Stext:
- Handles requests from Smain for storing and retrieving
.txt
files.
- Handles requests from Smain for storing and retrieving
The client supports the following commands:
-
ufile filename destination_path
:- Uploads a file to Smain.
- Smain handles redirection to Spdf or Stext if necessary.
-
dfile filename
:- Downloads a file from Smain.
- Smain retrieves the file from the appropriate server if needed.
-
rmfile filename
:- Removes a file from Smain.
- Smain requests deletion from Spdf or Stext if necessary.
-
dtar filetype
:- Creates a tar file of the specified type (
.c
,.pdf
, or.txt
) and downloads it.
- Creates a tar file of the specified type (
-
display pathname
:- Lists all files of type
.c
,.pdf
, and.txt
in the specified directory.
- Lists all files of type
-
Compile the Code:
gcc -o Smain Smain.c gcc -o Spdf Spdf.c gcc -o Stext Stext.c gcc -o client24s client24s.c
-
Run the Servers:
- Start Smain on one terminal:
./Smain
- Start Spdf on another terminal:
./Spdf
- Start Stext on a third terminal:
./Stext
- Start Smain on one terminal:
-
Run the Client:
./client24s
-
Example Commands:
- Upload a file:
client24s$ ufile sample.c ~smain/folder1/folder2
- Download a file:
client24s$ dfile ~smain/folder1/folder2/sample.c
- Remove a file:
client24s$ rmfile ~smain/folder1/folder2/sample.c
- Create a tar file:
client24s$ dtar .c
- Display files:
client24s$ display ~smain/folder1
- Upload a file:
- Ensure that all servers and the client are running on different machines/terminals.
- Paths are case-sensitive, and directory structures must be created as needed.
- Proper error handling is implemented for command validation and network issues.