SHARE
TWEET

Untitled

a guest Oct 21st, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import socket  # Import socket module
  2. import sys
  3. import os
  4. import time
  5.  
  6. if len(sys.argv) is not 4:
  7.     print('Usage: python3 send_file.py ip port filename')
  8.     sys.exit(-1)
  9.  
  10. s = socket.socket()  # Create a socket object
  11. host = sys.argv[1] # Ip address that the TCPServer  is there
  12. port = int(sys.argv[2])  # Reserve a port for your service every new transfer wants a new port or you must wait.
  13.  
  14. s.connect((host, port))
  15.  
  16. filename = sys.argv[3]
  17.  
  18. s.send(bytes(filename, encoding='utf8'))
  19. print(s.recv(1024).decode())
  20.  
  21. f = open(filename, 'rb')
  22. size = os.path.getsize(filename)
  23. buff = f.read(1024)
  24.  
  25. i = 0
  26. while buff:
  27.     s.send(b'pk')
  28.     s.send(buff)
  29.     i += 1
  30.     print('Progress: ' + str((1024 / (size/100)) * i), end='\r')
  31.     buff = f.read(1024)
  32.     time.sleep(0.1)
  33.  
  34.  
  35. print('Progress: 100')
  36.  
  37. s.send(b'ok')
  38. f.close()
  39. s.close()
  40. print('File sent.')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top