Advertisement
frolkin28

client.py

Oct 27th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. import socket
  2. import subprocess
  3. import os
  4.  
  5.  
  6. def main():
  7.     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  8.     s.connect(('127.0.1.1', 8097))
  9.     command, file_name = s.recv(1024).split()
  10.  
  11.     # parsing message from server
  12.     command, file_name = str(command, 'utf-8'), str(file_name, 'utf-8')
  13.     input_file = os.path.abspath(file_name)
  14.     target_file = input_file.replace(file_name, 'copy_' + file_name)
  15.  
  16.     # make a copy of file in the same directory
  17.     with open(target_file, 'w') as f:
  18.         # print(' '.join([command, input_file, target_file]))
  19.         # os.system(' '.join([command, input_file, target_file]))
  20.         subprocess.run([command, input_file, target_file])
  21.  
  22.     # send a copy to a server
  23.     with open(target_file, 'rb') as f:
  24.         data = f.read(1024)
  25.         while data:
  26.             print('Sending')
  27.             s.send(data)
  28.             data = f.read(1024)
  29.     s.send(b'^__^')
  30.     s.shutdown(2)
  31.     s.close()
  32.  
  33.  
  34. if __name__ == '__main__':
  35.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement