| |

VerySource

 Forgot password?
 Register
Search
View: 797|Reply: 5

Libcurl can achieve file upload, how do I implement file download? Urgent

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-4 16:20:01
| Show all posts |Read mode
The following code can upload the specified file in the specified directory to the specified directory on an HTTP server
curl_global_init (CURL_GLOBAL_ALL);
curl_formadd (&formpost,&lastptr, CURLFORM_COPYNAME, "file_name", CURLFORM_FILE, filepath, CURLFORM_END);
if (httpflag == 0) {
curl_formadd (&formpost,&lastptr, CURLFORM_COPYNAME, "buttom2", CURLFORM_COPYCONTENTS, "UPLOAD", CURLFORM_END);
} else if (httpflag == 1) {
curl_formadd (&formpost,&lastptr, CURLFORM_COPYNAME, "buttom1", CURLFORM_COPYCONTENTS, "UPLOAD", CURLFORM_END);
}
timevalue = conf_get_prop ("General", "UploadTimeout");
if (timevalue == NULL) {
TR_MALLOC (timevalue, 10);
TR_STRNCPY (timevalue, DEF_UPLOAD_TIME, 10);
}
curl = curl_easy_init ();
if (curl) {
// curl_easy_setopt (curl, CURLOPT_HEADER, TRUE);
curl_easy_setopt (curl, CURLOPT_URL, url);
curl_easy_setopt (curl, CURLOPT_USERPWD, userpwd);
curl_easy_setopt (curl, CURLOPT_POST, TRUE);
curl_easy_setopt (curl, CURLOPT_TIMEOUT, atoi (timevalue));
curl_easy_setopt (curl, CURLOPT_HTTPPOST, formpost);
res = curl_easy_perform (curl);
}


How to use Libcurl to realize the download of the specified file on the HTTP server to the specified directory? Urgent !!! Thank you
Reply

Use magic Report

0

Threads

24

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-1-5 13:57:01
| Show all posts
What else do I fix?
Now just execute it from the command line
Learn to say 喽
Reply

Use magic Report

0

Threads

24

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-1-5 15:03:01
| Show all posts
Installed a lib library, you can use the command line
For example, the next file can be like this
system ("curl www.baidu.com/test.exe> ​​1.exe");

You can download a test.exe file from Baidu to the local computer and name it 1.exe
Reply

Use magic Report

0

Threads

11

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 Invalid IP Address

Post time: 2020-1-6 20:54:01
| Show all posts
Halo ... the curl's documentation teaches how to download, it's nothing more than constructing an easy handle and then setting the request. .
Reply

Use magic Report

0

Threads

36

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

Post time: 2020-1-7 13:00:01
| Show all posts
Install an exe, set the path, and then system is fine
Reply

Use magic Report

0

Threads

18

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-1-29 06:09:02
| Show all posts
Learn to learn.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list