title: Upload a file to a web server using C++
body: <p>I want to upload files from a client location to a server. At present, I have a client-server socket program by which I could send/receive files across, but I would like to improvise it. </p>
  
  <p>My idea would be to transfer the file using HTTP PUT/POST from client (most of the coding on client side) to the server. Since I have no idea about HTTP programming, so I need some guidance on how to achieve that. I want to use C++ with BSD sockets in doing that, and no other libraries. My aim is to <em>send</em> the server a form, like as given below with a HTTP POST/PUT request, and get the file "main.cpp" uploaded to the server. </p>
  
  <pre><code>PUT http://localhost/ HTTP/1.0
  Host: localhost
  Content-type: form-data
  Content-length: 90
  FileUpload: /Users/SG/files/main.cpp
  </code></pre>
  
  <p>I was able to write a dummy program that does some PUT from a client, and the web server running Apache returns a HTTP 200.  What I am failing to understand currently would be the following two things, which I guess are somewhat connected:</p>
  
  <ol>
  <li><p>How one could specify a file to be uploaded from the client in the form above? </p></li>
  <li><p>If I understand correctly, the file would be read at client site and then the file content would be sent to the server, where a server side script would read the bytes from client and create a copy of the file at the server. Is it correct?  </p></li>
  </ol>
  
  <p>Any help is appreciated.</p>
  
  <p>Thanks,<br>
  Sayan</p>