1. Sending a file from a client to a server

There is probably a better way to do this, but I embarked upon a search for a method to send information to and retrieve information from a webserver (that I control) a few days ago and this is what I ended up with:

1) Webserver

a) Enable cgi b) Enable exwc.exe as interpreter c) Install "myserverprocess.ex" (see below) in the cgi directory

2) Client side

a) using the eulibCurl.ew library, along with a single change (or not, as your preference, see below), Install "myclientprocess.ex" on the client machine.

Run the myclientprocess.ex. That's it. Below are my myserverprocess and myclientprocess files.

myserverprocess.ex

include file.e 
include get.e 
 
integer fn, multiplier, numeric_content_length 
sequence content_length, data 
atom temp 
 
multiplier = 1 
 
content_length = getenv("CONTENT_LENGTH") 
numeric_content_length = 0 
 
for i = length(content_length) to 1 by -1 do 
	numeric_content_length += multiplier * (content_length[i] - 48) 
	multiplier *= 10 
end for 
 
fn = open("myoutputfile.dat","w") 
	data = get_bytes(0,numeric_content_length) 
	puts(fn,data) 
close(fn) 
 
puts(1,"Content-type: text/html\n\n") 
puts(1,"Your file has been received!") 
 
-- *** end myserverprocess.ex 
 
-- *** myclientprocess.ex 
 
include c:\euphoria\eulibcurl.ew 
 
atom easyhandle 
sequence data 
object a 
 
easyhandle = curl_easy_init() 
 
data="This is the data" 
 
-- You may use the following line if you update the contants in 
--  eulibcurl.ew to include CURLOPT_POSTFIELDS = 10015 
--a=curl_easy_setopt(easyhandle, CURLOPT_POSTFIELDS, data) 
-- otherwise use 
a=curl_easy_setopt(easyhandle, 10015, data) 
 
-- change the destination server/port/process as appropriate 
a=curl_easy_setopt(easyhandle, CURLOPT_URL, "http://127.0.0.1:80/cgi-bin/myserverprocess.ex") 
a=curl_easy_perform(easyhandle) 
curl_easy_cleanup(easyhandle) 
 
-- 

I think that is it. When you run myclientprocess.ex it contacts the server, at the port specified. Runs the myserverprocess.ex euphoria program and receives as return value that which is found on the last two line of the server process.

I tested a sequence of 500,000 bytes stuffed into "data" and it worked. That is big enough for my purposes. My guess is that it is therefore unlimited in size.

Mike777

new topic     » topic index » view message » categorize

2. Re: Sending a file from a client to a server

And just in case anybody thinks the above is the final version for production use, rest assured that I stripped all of the error checking, debug information and user interface messages out before posting. I wanted to display the logic of getting it done, not how I yell at my users. :)

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu