Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- import subprocess
- import os
- def main():
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- s.connect(('127.0.1.1', 8097))
- command, file_name = s.recv(1024).split()
- # parsing message from server
- command, file_name = str(command, 'utf-8'), str(file_name, 'utf-8')
- input_file = os.path.abspath(file_name)
- target_file = input_file.replace(file_name, 'copy_' + file_name)
- # make a copy of file in the same directory
- with open(target_file, 'w') as f:
- # print(' '.join([command, input_file, target_file]))
- # os.system(' '.join([command, input_file, target_file]))
- subprocess.run([command, input_file, target_file])
- # send a copy to a server
- with open(target_file, 'rb') as f:
- data = f.read(1024)
- while data:
- print('Sending')
- s.send(data)
- data = f.read(1024)
- s.send(b'^__^')
- s.shutdown(2)
- s.close()
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement