I want to upload files from a client location to a server. I currently have a socket-client-server program with which I can send / receive files, but I would like to improvise.
My idea would be to transfer the file using HTTP PUT / POST from the client (most of the code is client-side) to the server. Since I have no idea about HTTP programming, so I need to be guided by how to achieve this. I want to use C ++ with BSD sockets for this and no other libraries. My goal is to send the server a form as indicated below with an HTTP POST / PUT request, and get the file "main.cpp" uploaded to the server.
PUT http://localhost/ HTTP/1.0
Host: localhost
Content-type: form-data
Content-length: 90
FileUpload: /Users/SG/files/main.cpp
I managed to write a dummy program that runs some PUT from the client, and the web server running Apache returns HTTP 200. What I don’t understand at the moment would be the following two things, which I think are somewhat related
How can I specify the file that will be downloaded from the client in the form above?
If I understand correctly, the file will be read on the client site, and then the contents of the file will be sent to the server, where the server side of the script will read bytes from the client and create a copy of the file on the server. Is it correct?
Any help is appreciated.
Thanks,
Sayansk
Sayan source
share