LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices



Reply
 
Search this Thread
Old 06-11-2012, 10:04 AM   #1
lievendp
Member
 
Registered: Jan 2006
Location: Belgique
Distribution: Gentoo, Debian, Redhat, Centos, (x)Ubuntu
Posts: 111

Rep: Reputation: 27
CURL uploading file with POST


I've been trying to upload files with curl using the POST method. Obviously, this is done to get a bash-script to upload files to my site.

Googled a lot of examples and read the man page but none of the methods seem to work...

This is how I run curl:
#.> curl -F fl=@localfile -F press=K http://<internaliport>

There is a simple form saved as index.html on the root of this page and this is the form:
<form method="POST" enctype='multipart/form-data' action="cgi-bin/upload.cgi">
<input type="file" name="fl">
<input type="submit" name="press" value="K">
</form>

I use "fl=@localfile" as it is supposed to send the whole file, it's a simple ascii file.
the "press=K" refers to the submit button.

When I surf my website and manually fill in the form, there is no problem at all, I can upload the local file to the server so the perl cgi file in the backend is ok. (upload.cgi)

All I get from curl though is just a dump of the html file...


Notice that I also tried with -d but to no avail. Form should be the way to go.

thanks for any hints.

Last edited by lievendp; 06-11-2012 at 10:06 AM.
 
Old 06-11-2012, 12:14 PM   #2
lievendp
Member
 
Registered: Jan 2006
Location: Belgique
Distribution: Gentoo, Debian, Redhat, Centos, (x)Ubuntu
Posts: 111

Original Poster
Rep: Reputation: 27
What I think strange is that with curl, I see no reference to the cgi upload script when I wireshark the connection.
With a normal browser session, I can see the POST refer to the cgi-bin/upload.cgi instead of just POST / HTTP1.1

CURL:
10 0.043058 <clientip> <serverip> HTTP POST / HTTP/1.1 (application/octet-stream)

BROWSER:
15 5.303280 <clientip> <serverip> HTTP POST /cgi-bin/upload.cgi HTTP/1.1 (text/plain)

so I changed the application type but no joy, the prolbem seems that there is no reference to the upload.cgi script with curl:
curl --user-agent Mozilla -v -H"Content-Type:text/plain" -F fl=@tst1 -F press=K http://<serverip>:<port>/
30 4.279270 <clientip> <serverip> HTTP POST / HTTP/1.1 (text/plain)

Any thoughts?

thanks.
 
Old 06-12-2012, 03:42 AM   #3
lievendp
Member
 
Registered: Jan 2006
Location: Belgique
Distribution: Gentoo, Debian, Redhat, Centos, (x)Ubuntu
Posts: 111

Original Poster
Rep: Reputation: 27
Well, it turns out that I cannot upload the file using the html form page. Instead, it works when I talk directly to the cgi script:
curl --user-agent Mozilla -v -F "fl=@tst1" http://<serverip>:<serverport>/cgi-bin/upload.cgi

Now the file is uploaded correctly. I assumed that the -F meant that I had to talk to the form but I was wrong apparently.
 
  


Reply

Tags
curl, post, upload


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Curl html post problem ericdumas Linux - Server 0 09-08-2011 09:04 AM
cURL newbie. Need help with what to post etrump Linux - Newbie 5 07-13-2011 02:11 PM
[perl] uploading a file using POST s0l1dsnak3123 Programming 2 05-12-2008 03:38 PM
uploading file with POST from PHP issue lukebeales Programming 2 04-23-2008 09:54 PM
Problem in uploading using Curl command. rmvinodh123 Programming 0 05-04-2007 12:36 PM


All times are GMT -5. The time now is 10:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration