title: How to send multiple files concurrently from a folder using socket programming in Python
body: <p>I am new to Python programming. I want to write a socket program that allows a client to send multiple files (with concurrency) from a folder to a server. For example, a client creates a folder <code>My Folder</code> with 150 files and send the files with concurrency 2, 4, and 6 from the folder to the server. That is, the client sends 2, 4, and 6 files at a time to the sever until the 150 files are sent. The application should support integrity verification where the client and the server calculate checksum of each file and compare. But now, my program only send one file from the client to the server.</p>
  <p>client.py</p>
  <pre class="lang-py prettyprint-override"><code>import hashlib
  import socket
  import tqdm
  import os
  
  SEPARATOR = &quot;&lt;SEPARATOR&gt;&quot;
  BUFFER_SIZE = 25 * 1024
  host = &quot;127.0.0.1&quot;
  port = 5050
  filename = &quot;file\data.xlsx&quot;
  filename = hashlib.sha3_512().hexdigest()
  filesize = os.path.getsize(filename)
  s = socket.socket()
  print(f&quot;[+] Connecting to {host}:{port}&quot;)
  s.connect((host, port))
  print(&quot;[+] Connected.&quot;)
  s.send(f&quot;{filename}{SEPARATOR}{filesize}&quot;.encode())
  progress = tqdm.tqdm(range(filesize), f&quot;Sending {filename}&quot;, unit=&quot;B&quot;, unit_scale=True, unit_divisor=1024)
  with open(filename, &quot;rb&quot;) as f:
      while True:
          bytes_read = f.read(BUFFER_SIZE)
          if not bytes_read:
              break
          s.sendall(bytes_read)
          progress.update(len(bytes_read))
  print('Successfully send the file')
  s.close()
  print('Connection Closed!')
  </code></pre>
  <p>server.py</p>
  <pre class="lang-py prettyprint-override"><code>import socket
  import os
  import tqdm
  import threading
  import hashlib
  SERVER_HOST = &quot;127.0.0.1&quot;
  SERVER_PORT = 5050
  BUFFER_SIZE = 25 * 1024
  SEPARATOR = &quot;&lt;SEPARATOR&gt;&quot;
  s = socket.socket()
  s.bind((SERVER_HOST, SERVER_PORT))
  s.listen(5)
  print(f&quot;[*] Listening as {SERVER_HOST}:{SERVER_PORT}&quot;)
  client_socket, address = s.accept()
  print(f&quot;[+] {address} is connected.&quot;)
  rcv = client_socket.recv(BUFFER_SIZE).decode()
  filename, filesize = rcv.split(SEPARATOR)
  filename = os.path.basename(filename)
  filesize = int(filesize)
  progress = tqdm.tqdm(range(filesize), f&quot;Receiving {filename}&quot;, unit=&quot;B&quot;, unit_scale=True, unit_divisor=1024)
  with open(filename, &quot;wb&quot;) as f:
      while True:
          bytes_read = client_socket.recv(BUFFER_SIZE)
          if not bytes_read:
              break
          f.write(bytes_read)
          progress.update(len(bytes_read))
  client_socket.close()
  print('File successfully received')
  s.close()
  print('Connection closed!')
  
  </code></pre>