-
Notifications
You must be signed in to change notification settings - Fork 0
/
Files_Transmit.py
39 lines (31 loc) · 1.06 KB
/
Files_Transmit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#--------------------//SERVER//-----------------------#
import socket
from thread import *
import os
def RetrFile(name, sock):
while True:
filename = raw_input('Enter path of filename to send: ')
if os.path.isfile(filename):
sock.send(filename + '`' + str(os.path.getsize(filename)))
userResponse = sock.recv(2048)
if userResponse[:2] == 'OK':
with open(filename, 'rb') as f:
bytesToSend = f.read(2048)
sock.send(bytesToSend)
while bytesToSend != "":
bytesToSend = f.read(2048)
sock.send(bytesToSend)
else:
print("ERR ")
host = ''
port = 5000
s = socket.socket()
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((host,port))
s.listen(5)
print "Server Started."
while True:
c, addr = s.accept()
print "client connedted ip:<" + str(addr) + ">"
start_new_thread(RetrFile, ("RetrThread", c))
s.close()