ViniCastilho

cdp-b2-t1-servidor-backup.py

Jun 28th, 2025
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. import socket;
  2.  
  3. # /home/a221251782/Monitoramento/
  4. BACKUPFILEPATH = 'log-backup.log'
  5. SERVERHOST = 'localhost';
  6. SERVERPORT = 8191;
  7.  
  8. def startserver():
  9. with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as server:
  10. SERVERTUPLE = (SERVERHOST, SERVERPORT);
  11. server.bind(SERVERTUPLE);
  12. server.listen();
  13. print(f'LISTENING AT {SERVERHOST}:{SERVERPORT}');
  14.  
  15. while True:
  16. conn, addr = server.accept();
  17. with conn:
  18. data = conn.recv(4096).decode();
  19. if data:
  20. with open(BACKUPFILEPATH, 'a') as fh:
  21. fh.write(f'{data}\n');
  22. #with:
  23. print(f'APPENDED FROM {addr}');
  24. #if:
  25. #with:
  26. #while:
  27. #with:
  28. #def:
  29.  
  30. if __name__ == '__main__': startserver();
Advertisement
Add Comment
Please, Sign In to add comment