11def hashfile(blockfile):
12 for block
in blockfile:
13 hashlib.sha256().update(block)
14 return hashlib.sha256().hexdigest()
18 block = filed.read(Blocksize)
21 block = filed.read(Blocksize)
23def send_file_server(client,TileSet,pathin,filename,pathout):
24 filein=os.path.join(pathin,filename)
25 filesize = os.path.getsize(filein)
26 filed=open(filein,
'rb')
27 filesha256=hashfile(readblock(filed))
29 command=
'putfile TS='+TileSet+
" "+pathout+
" "+filename+
" "+str(filesize)+
" "+str(filesha256)
30 print(
"Command putfile : %s" % (command))
31 client.send_server(command)
32 print(
"Out of send command %s" % (str(client.get_OK())))
33 client.send_file(pathin,filename)
34 print(
"Out of send file %s" % (str(client.get_OK())))
36 if oct((os.stat(filein).st_mode & stat.S_IRWXU+stat.S_IRWXG+stat.S_IRWXO) > stat.S_IRWXU) == oct(1):
37 command=
'launch TS='+TileSet+
" "+pathout+
" chmod u+x "+filename
38 client.send_server(command)
39 print(
"Chmod %s : %s" % (pathout, str(client.get_OK())))
42def get_file_client(client,TileSet,pathserv,filename,pathout):
43 command=
'askfile TS='+TileSet+
" "+pathserv+
" "+filename
44 print(
"Command askfile : %s" % (command))
45 client.send_server(command)
46 print(
"Out of ask command and file exists %s" % (str(client.get_OK())))
49 fileinfos=client.recv()
50 if not fileinfos
or fileinfos == 0:
51 print(
"Error with fileinfos %s" % (str(fileinfos)))
54 print(
"Retrieve fileinfos : %s" % (str(fileinfos)))
57 if (re.search(
r'fileinfos',fileinfos)):
58 p=re.compile(
r'fileinfos ([^ ]*) ([0-9]*) ([a-z0-9]*)')
59 CommandFilename=p.sub(
r'\1',fileinfos)
60 CommandSize=int(p.sub(
r'\2',fileinfos))
61 CommandSha256=p.sub(
r'\3',fileinfos)
64 print(
"File transfer with filename %s with size %d and sha256 %s " % (CommandFilename,CommandSize,CommandSha256))
66 client.get_file(pathout,filename,CommandSize,CommandSha256)
67 print(
"Out of get file %s" % (str(client.get_OK())))
68 return(int(CommandSize))