Transfer the files from one place or mobile to another using Python

Using socket programming , we can transfer file from computer to computer, computer to mobile, mobile to computer.

Python Code:

Server Code:

import socket
import os
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.bind(('192.168.43.204', 5001))

s.listen(10)
c,addr=s.accept()
print('{} Connected.'.format(addr))
f=open('video.mp4','rb')
data_in=f.read(1024)

while data_in:
    c.send(data_in)
    data_in=f.read(1024)
f.close()
print("done sending")

Client Code:

import socket
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect(("192.168.43.204",12345))
f=open("video.mp4",'wb')

while True:
    data_in=s.recv(1024)
    while data_in:
        f.write(data_in)
        data_in=s.recv(1024)
    f.close()
    break
print("file recieved")

Output: transferring file computer to mobile

when we run server side program , simultaneously we run client file on mobile and client got connected with server
when we run the program, file is recieved in mobile

This project is contributed by Kajal Chaudhary


0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Insert math as
Block
Inline
Additional settings
Formula color
Text color
#333333
Type math using LaTeX
Preview
\({}\)
Nothing to preview
Insert