title: Need to transfer multiple files from client to server
body: <p>I'm recently working on a project in which I'm basically making a dropbox clone. The server and client are working fine but I'm having a slight issue. I'm able to transfer a single file from the client to the server but when I try to transfer all the files together it gives me an error after the transfer of the first file so basically my code is only working for a single file. I need to make it work for multiple files. Any help will be appreciated. Here's my code</p>
  
  <p><strong>Server Code</strong></p>
  
  <pre><code>import socket
  import thread
  import hashlib
  
  serversock = socket.socket()
  host = socket.gethostname();
  port = 9000;
  serversock.bind((host,port));
  filename = ""
  serversock.listen(10);
  print "Waiting for a connection....."
  
  clientsocket,addr = serversock.accept() 
  print("Got a connection from %s" % str(addr))
  while True:
      size = clientsocket.recv(1)
      filesz = clientsocket.recv(1)
      if filesz.isdigit():
          size += filesz
          filesize = int(size)
      else:
          filesize = int(size)    
      print filesize
      for i in range(0,filesize):
          if filesz.isdigit():
              filename += clientsocket.recv(1)
          else:
              filename += filesz
              filesz = "0"
      print filename      
      file_to_write = open(filename, 'wb')
      while True:
          data = clientsocket.recv(1024)
          #print data
          if not data:
              break
          file_to_write.write(data)
      file_to_write.close()
      print 'File received successfully'
  serversock.close()
  </code></pre>
  
  <p><strong>Client Code</strong></p>
  
  <pre><code>import socket
  import os
  import thread
  
  s = socket.socket() 
  host = socket.gethostname()                           
  port = 9000
  s.connect((host, port))
  path = "C:\Users\Fahad\Desktop"
  directory = os.listdir(path)
  for files in directory:
      print files  
      filename = files
      size = bytes(len(filename))
      #print size
      s.send(size)
      s.send(filename)
      file_to_send = open(filename, 'rb')
      l = file_to_send.read()
      s.sendall(l)
      file_to_send.close()       
      print 'File Sent'                                              
  s.close()                                                                           
  </code></pre>
  
  <p><strong>Here's the error that I get</strong></p>
  
  <pre><code>Waiting for a connection.....
  Got a connection from ('192.168.0.100', 58339)
  13
  Betternet.lnk
  File received successfully
  Traceback (most recent call last):
    File "server.py", line 22, in &lt;module&gt;
      filesize = int(size)
  ValueError: invalid literal for int() with base 10: ''
  </code></pre>