-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.py
83 lines (68 loc) · 2.1 KB
/
client.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# receive
import socket
import hashlib
import struct
import os
import tqdm
HOST = '192.168.31.89'
PORT = 1080
BUFFER_SIZE = 1024
HEAD_STRUCT = '128sIq32s'
info_size = struct.calcsize(HEAD_STRUCT)
COD = 'utf-8'
def requrest_filelist(dirname):
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = (HOST, PORT)
client_socket.connect(server_address)
send_data = dirname.encode(COD)
client_socket.send(send_data)
recved_size = 0
with open("cache.txt", 'wb') as fw:
while True:
recv_file = client_socket.recv(BUFFER_SIZE)
if len(recv_file) <= 0:
break
else:
fw.write(recv_file)
def make_dirs(directory):
path, filename = os.path.split(directory)
dirs = path.split('\\')
dir = ''
for i in dirs:
dir += i
dir += '/'
if not os.path.exists(dir):
os.mkdir(dir)
def download_file(url, output):
make_dirs(output)
print(output)
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = (HOST, PORT)
client_socket.connect(server_address)
send_data = url.encode(COD)
client_socket.send(send_data)
recved_size = 0
with open(output, 'wb') as fw:
while True:
recv_file = client_socket.recv(BUFFER_SIZE)
if len(recv_file) <= 0:
break
else:
fw.write(recv_file)
if __name__ == '__main__':
path_planning = 'F:/1211/3DGLueGuider'
dirname = "F:\\1126"
dirname = path_planning
requrest_filelist(dirname)
with open("cache.txt") as f:
for line in tqdm.tqdm(f.readlines(), 'downloading...'):
if line.find('.vs') != -1:
continue
if line.find('x64') != -1:
continue
if line.find('.git') != -1:
continue
line = line.strip()
url = line
output = f'downloads{line[len(dirname):]}'
download_file(url, output)