0% found this document useful (0 votes)
20 views

Ftpalgo

Uploaded by

rahanachirakkal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Ftpalgo

Uploaded by

rahanachirakkal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 5

FILE TRANSFER PROTOCOL

Aim: To develop a concurrent file server which will provide the file requested by the
client if it exists. If not, the server sends appropriate messages to the client. Server
sends its process ID (PID) to clients for display along with the file or the message.

Description:

The file server creates listening sockets on two ports that have consecutive port
numbers. One is the listening socket for control connection and the other is the
listening socket for data connection. These sockets have descriptors listen_control
and listen_data respectively. The client creates a socket and connects to the server
using TCP connection. The client socket descriptor is stored in sock_ctrl. The server
creates a connection socket when the client makes a TCP connection with the server.
This connection socket is stored in sock_ctrl. This connection is for control
information to pass between client and server. Next, the server forks a child process.
Since the child is a perfect image of its parent, the child process will also have
descriptors listen_control, listen_data and sock_ctrl. The control connection will also
be duplicated between the client and the child process. The child process closes its
listening socket for control connection, i.e; listen_control. The parent server process
closes its connection socket for the control connection i.e; sock_ctrl. The client now
makes a TCP connection with the server for transferring data stored in sock_data.
The connection socket for the data connection is stored in sock_data in the server
child process.

Algorithm

Client

1. Create the client TCP control connection to a port (port_num) of the server
with the client socket descriptor sock_ctrl.

2. `while(1)

{
1. Create client socket descriptor sock_data for the data connection with

server on another port (portnum + 1). For each file transfer a new data

connection is required.

2. Read the command from the terminal given by the user

3. Send the command to the server using control socket sock_ctrl.

4. If command == “close”
close sock_data and sock_ctrl
break
5. Enter the filename using the keyboard

6. Write the filename using control socket sock_ctrl to the server.

7. Use while(connect(...) < 0) to wait for the data connection.

8. read data using sock_data (file contents) from the server and write to the file

9. If file does not exist print the process id of server


}

Server

1. Initialize variable file_present to 1

2. Create listening socket for the control connection on port (port_num) and store it in

listen_control.

3. Create a listening socket for the data connection on port (port_num +1) and store it in
listen_data
4. while (1)

1. accepts the client control connection and returns the connect socket descriptor

sock_ctrl

2. fork a child process

1. if(childprocess)

close listening socket listen_control

while(1)

read command from the client on the control connection

if command

==

“close

break

else

read the filename from the client using control connection open the file
if (no file)

form a string “@FILE NOT FOUND PROCESS ID = getprocess id” and store it in

variable buffer

file_present = 0;

accept the data connection and return the socket descriptor sock_data

if(file_present)

read file contents and write to sock_data

form a string “FILE filename RECEIVED FROM SERVER WITH PROCESS ID =

getprocess id” and store it in variable buffer

else

file_present = 1;

write buffer using sock_data to the client

close sock_data

close(sock_ctrl) close(listen_data) child

process exits

close( sock_ctrl)
}

5. close(listen_control);

close(listen_data);

You might also like