Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

using(python2.7) Write a function exercise29(filename, IP) to transfer a file to

ID: 3835139 • Letter: U

Question

using(python2.7)

Write a function exercise29(filename, IP) to transfer a file to another computer. Inputs: filename: a string indicating the path of the file to be transmitted. IP: a string indicating the path of the destination computer. Example: exercise29('c:/cat.jpg', '10.40.0.1') should transfer 'cat.jpg' in the computer that runs this program to another computer whose IP address is 10.40.0.1

. Remarks: 1. To ensure file transmission, you probably need to also write another function to receive the file, and run this function at the destination computer.

please I want somthing that really works

Explanation / Answer

When we transfer a file we have to use something called as send() in python.

For connection, to the server, we have to use something called as socket.io

Find the below code for the above problem statement:

********

import socket
import sys
s = socket.socket()
s.bind(("10.40.0.1",3000))
s.listen(10)
i=1
while True:
sc, address = s.accept()
print address
f = open("c:/cat.jpg",'wb') #open in binary

l = 1
while(l):
l = sc.recv(1024)
while (l):
f.write(l)
l = sc.recv(1024)
f.close()
sc.send("received") # Would like to send back a response

sc.close()

s.close()
------------------------------------------------------------
#client
import socket
s = socket.socket()
s.connect(("10.40.0.1",3000))
f=open ("c:/cat.jpg", "rb")
l = f.read(1024)
while (l):
s.send(l)
l = f.read(1024)
s.shutdown(socket.SHUT_WR)
reply =s.recv(1024) # Feedback: would like the receive feedback from the server.
print reply
s.close()