Environment:
Windows 64 cURL build
C:>curl64.exe -V(ersion)
- curl 7.53.1 (x86_64-w64-mingw32) libcurl/7.53.1 WinSSL zlib/1.2.8 WinIDN libssh2/1.7.0_DEV
- Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smtp smtps telnet tftp
- Features: IDN IPv6 Largefile SSPI Kerberos SPNEGO NTLM SSL libz
My website has a PHP package for file downloads that requires an HTTP Post to specify the file to download.
When I am using a browser, I get a OPEN with/SAVE dialog and I can save the file to my computer with no problem. When I am using cURL, the requested file just streams to the console.
How do I do a cURL HTTP Post request to download a file and then save it?
- Lots of examples for uploading a file with a Post...
- Lots of examples for doing a Post in general...
- Lots of examples for simply downloading files (-O/o)...
But I can't find an example of saving the file that a Post command returns.
I've tried these three curl command lines:
C:>curl64.exe -d "download=XYZ.zip&email=&submit=Download" http://www.example.com/downloads/dl.php
C:>curl64.exe -d "download=XYZ.zip&email=&submit=Download" -O XYZ.zip http://www.example.com/downloads/dl.php
curl: Remote file name has no length!
C:>curl64.exe -d "download=XYZ.zip&email=&submit=Download" http://www.example.com/downloads/dl.php > XYZ.zip
Access is denied.
In the first two examples, the file contents are streamed to the console instead of the file being saved or giving me an option to save it.
In the third example, I tried to redirect the output, but got an "Access is denied." error. I'm a local admin on the Windows system. I've tried different directories. Still get the same error.
Answer
After LOTS of reading (all night)... I figured out that it's obviously bad to do research when you are burned out and should really be sleeping instead. [grin]
Earlier, I saw too many cURL examples where some used the -O option and others that used the -o option for file downloads. As everything blurred together for me, I didn't realize that they were two DIFFERENT options. After reading the cURL help for the hundredth time, I finally saw the difference:
- -O is for DOWNLOADING a file
- -o is for REDIRECTING cURL's output to a file instead of to stdout
This command line works:
C:\cURLtest>curl64.exe -d "download=XYZ.zip&email=&submit=Download" -o XYZ.zip http://www.example.com/downloads/dl.php
To anyone that spent time researching the issue (that wasn't)... Please excuse this dummy for wasting your time.
No comments:
Post a Comment