0% found this document useful (0 votes)
70 views5 pages

Implement A File Transfer Server Using TCP Sockets. Procedure: 1

The document describes implementing a file transfer server using TCP sockets in Python. It includes: 1. The server creates a socket, binds it to port 8018, listens for connections, accepts a connection from a client, receives data from the client, writes the data to a file, and sends the file to the client. 2. The client connects to the server, sends a message to the server, receives the file from the server and writes it to a file, then closes the connection. 3. The program was successfully implemented and able to transfer a file from the server to client using TCP sockets.

Uploaded by

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

Implement A File Transfer Server Using TCP Sockets. Procedure: 1

The document describes implementing a file transfer server using TCP sockets in Python. It includes: 1. The server creates a socket, binds it to port 8018, listens for connections, accepts a connection from a client, receives data from the client, writes the data to a file, and sends the file to the client. 2. The client connects to the server, sends a message to the server, receives the file from the server and writes it to a file, then closes the connection. 3. The program was successfully implemented and able to transfer a file from the server to client using TCP sockets.

Uploaded by

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

JEYASANKR C

18UCSE090
2.

Aim:

Implement a File Transfer Server using TCP Sockets.

Procedure:

1.Start the program.

2.Declare the variables and structures required.

3.The socket is created using the socket function.

4.The socket is binded to the specific port.

5.Start listening for the connections.

6.Accept the connection from the client.

7.Create a new file.

8.Receives the data from the client.

Program:

Server

import socket

s=socket.socket()

port=8018

host="localhost"

s.bind((host,port))

s.listen(5)

print('Server listening...')

conn,addr=s.accept()

print('Got connection from ',addr)

print('Data Connection Established @Port 21')


JEYASANKR C

18UCSE090

data = conn.recv(1024).decode()

print('Server received', repr(data))

filename='ftpser.py'

print('Data Transfer Started using @Port 20')

f=open(filename,'rb')

l=f.read(1024)

while (l):

conn.send(l)

print('sent',repr(l))

l=f.read(1024)

if l=="":

break

f.close()

conn.close()

print('Server listening...')

client

import socket

s=socket.socket()

host='localhost'

port=8018

s.connect((host,port))

s.send('Hello Server'.encode())
JEYASANKR C

18UCSE090
with open('ftpex.py','wb') as f:

print ('File opened')

while True:

print('Receiving data...')

data=s.recv(1024)

print(repr(data))

if not data:

break

f.write(data)

f.close()

print('Successfully get the file from Server')

s.close()

print('Connection closed')
JEYASANKR C

18UCSE090

Output:

server
JEYASANKR C

18UCSE090

Client

Result:

Thus the implementation of a File Transfer Server using TCP Sockets was successfully created.

You might also like