cURL / Mailing Lists / curl-users / Single Mail

curl-users

Uploading user-data to printer controller

From: Martijn Balink <bnk_at_hesasd.nl>
Date: Mon, 25 Apr 2005 13:16:04 +0200

Hi,
 
I want to use cURL to upload a file with usernames and pincodes to our printers (Océ Varioprint 2060). This is done through a web interface. I've managed to logon to the interface through cURL, and upload the file.
However, when I upload the file through a browser, the upload succeeds completely, when I upload the same file through cURL, the upload fails. All that the printer returns is a message saying "an unknown error has occured", which is, as far as I can remember, the only error it CAN produce (not very useful...;-)).
I've captured the network packets, the file does actually get uploaded to the printer, but the PHP-code running on the controller of the printer thinks the file is not correct.
In the captured packets, I've compared the network packets that my browser produces with the post requests that cURL creates (and the packets that the printer returns), and I don't see any difference.
The printercontroller is a black box, I can't get access to the PHP-code that's running on it.
 When you initially access the printer, a random cookie is generated to maintain your session once logged in. I save this cookie in a textfile called "cookiepot.txt" and use it again in the next instances of cURL.
 
This is the cURL-code I use:
------------------
REM request the logonpage, save the coockie.
curl -L -H "Connection: Keep-Alive" -H "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*" -H "Accept-Language: nl" -H "Accept-Encoding: gzip, deflate" -A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)" -c "cookiepot.txt" http://printer/websas/login/login.php?lang=GB <http://printer/websas/login/login.php?lang=GB>
 
REM login (give pincode) together with the cookie to confirm authentication
curl -L -b cookiepot.txt -d "password=12345&language=GB" http://printer/websas/login/login.php?lang=GB <http://printer/websas/login/login.php?lang=GB>
 
REM pass uploadfile to form, together with the cookie to confirm authentication
curl -L -H "Cache-Control: no-cache" -H "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*" -H "Accept-Language: nl" -H "Accept-Encoding: gzip, deflate" -A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)" -H "Referer: http://printer/websas/uploadfile.php <http://printer/websas/uploadfile.php> " -H "Connection: Keep-Alive" -b cookiepot.txt -F MAX_FILE_SIZE=100000 -F type=nccs -F client=MSIE -F "setfileID=@C:\USERFILE.CSV;type=application/vnd.ms-excel <mailto:setfileID=@C:\USERFILE.CSV;type=application/vnd.ms-excel> " http://printer/websas/hdl_uploadfile.php <http://printer/websas/hdl_uploadfile.php>
 
REM logoff
curl -L -b cookiepot.txt http://v36c/websas/login/logout.php <http://v36c/websas/login/logout.php>
------------------
 
I am aware of the fact that there's a lot of (probably unnecessary) rubbish in the code, I have added a lot of header information to exactly match my internet explorer requests. Anybody have any comments or tips how to get this thing working?
 
Thanks in advance,
 
Martijn Balink
Network administrator
Amsterdam School of Business
Received on 2005-04-25