title: How to download file from local server in Python
body: <p>Scenario is:</p>
  
  <ol>
  <li>Client will Enter a file name  e.g <strong>xyz</strong></li>
  <li>Server will show all the files that it have in different folders.</li>
  </ol>
  
  <p>Client will select 1 or 2 or 3 (if there). 
  and file will be downloaded. </p>
  
  <p><strong>I have done searching part.  I want help in downloading and saving the file in any other directory.</strong> </p>
  
  <p>My code so far is for searching the file. </p>
  
  <pre><code>import socket
  tcp_ip="127.0.0.1"
  tcp_port=1024
  buffer_size= 200
  filename=raw_input("Enter file name\n")
  
  s= socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  s.connect((tcp_ip,tcp_port))
  data=s.recv(buffer_size)
  s.close()
  </code></pre>
  
  <p>Server Code : (This code is now for one file) <strong>The required help is how to download and save that file which is found at server.</strong></p>
  
  <pre><code>import socket
  import os
  tcp_ip='127.0.0.1'
  tcp_port=1024
  buffer_size=100
  s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  s.bind((tcp_ip, tcp_port))
  s.listen(1)
  conn, addr = s.accept()
  print 'Connection Address:',addr
  while 1:
      data=conn.recv(buffer_size)
      if not data: 
          break
      else:
          print "received server side data:", data
      conn.send(data)
  conn.close()
  </code></pre>