SHARE
TWEET

Untitled

a guest Oct 21st, 2019 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import os
  2. import socket
  3.  
  4. import sys
  5.  
  6.  
  7. def main():
  8.     # AF_INET – IPv4, SOCK_STREAM – TCP
  9.     sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  10.  
  11.     file_name = sys.argv[1]
  12.     host_name = sys.argv[2]
  13.     port = int(sys.argv[3])
  14.  
  15.     try:
  16.         ip = socket.gethostbyname(host_name)
  17.     except socket.gaierror():
  18.         ip = host_name
  19.  
  20.     file = open(file_name, "rb")
  21.     sock.connect((ip, port))
  22.     sock.send(file_name.encode())
  23.     sock.recv(1)
  24.  
  25.     counter = 0
  26.     size = os.stat(file_name).st_size
  27.     while True:
  28.         data = file.read(1024)
  29.         if data == b'':
  30.             break
  31.  
  32.         counter += 1
  33.         print(100 * 1024 * counter / size)
  34.  
  35.         sock.send(data)
  36.  
  37.  
  38. if __name__ == "__main__":
  39.     main()
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
 
Top