Quote:
libcurl is a free and easy-to-use client-side URL transfer library, supporting FTP, FTPS, HTTP, HTTPS, SCP, SFTP, TFTP, TELNET, DICT, FILE and LDAP.
libcurl supports SSL certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, cookies, user+password authentication
(Basic, Digest, NTLM, Negotiate, Kerberos4), file transfer resume, http proxy tunneling and more!
libcurl is highly portable, it builds and works identically on numerous platforms, including Solaris, NetBSD, FreeBSD, OpenBSD, Darwin, HPUX, IRIX
, AIX, Tru64, Linux, UnixWare, HURD, Windows, Amiga, OS/2, BeOs, Mac OS X, Ultrix, QNX, OpenVMS, RISC OS, Novell NetWare, DOS and more...
libcurl is free, thread-safe, IPv6 compatible, feature rich, well supported, fast, thoroughly documented and is already used by many
known, big and successful companies and numerous applications.
Here's a simple example for downloading a file, while showing download progress.
The script requires
FileHelper.ahk.
You can directly download libcurl
here.
Code:
#SingleInstance, force
#NoEnv
#include FileHelper.ahk ; http://www.autohotkey.com/forum/topic19608.html
CURLOPT_URL := 0x2712
CURLOPT_WRITEDATA := 0x2711
CURLOPT_WRITEFUNCTION := 0x4E2B
CURLOPT_PROGRESSFUNCTION := 0x4E58
CURLOPT_NOPROGRESS := 0x2B
CURLOPT_ERRORBUFFER := 0x271A
CURLOPT_TRANSFERTEXT := 0x35
CURL_ERROR_SIZE := 0x100
Url = http://dl.google.com/earth/client/branded/redirect/Google_Earth_BZXV.exe
hFile := CreateFile(A_ScriptDir . "\Google_Earth_BZXV.exe", 1)
hModule := DllCall("LoadLibrary", "str", "libcurl-4.dll")
If !hModule
{
MsgBox, Error loading lib
ExitApp
}
MsgBox % Curl_Version()
hCurlEasy := DllCall("libcurl-4\curl_easy_init")
pCurl_WriteFunction := RegisterCallback("Curl_WriteFunction", "C F")
pCurl_ProgressFunction := RegisterCallback("Curl_ProgressFunction", "C F")
VarSetCapacity(CURL_ERROR, CURL_ERROR_SIZE + 1)
DllCall("libcurl-4\curl_easy_setopt", "UInt", hCurlEasy, "UInt", CURLOPT_ERRORBUFFER, "UInt", &CURL_ERROR, "Cdecl")
DllCall("libcurl-4\curl_easy_setopt", "UInt", hCurlEasy, "UInt", CURLOPT_URL, "Str", URL, "Cdecl")
DllCall("libcurl-4\curl_easy_setopt", "UInt", hCurlEasy, "UInt", CURLOPT_NOPROGRESS, "Int", 0, "Cdecl")
DllCall("libcurl-4\curl_easy_setopt", "UInt", hCurlEasy, "UInt", CURLOPT_PROGRESSFUNCTION, "UInt", pCurl_ProgressFunction, "Cdecl")
DllCall("libcurl-4\curl_easy_setopt", "UInt", hCurlEasy, "UInt", CURLOPT_WRITEFUNCTION, "UInt", pCurl_WriteFunction, "Cdecl")
If DllCall("libcurl-4\curl_easy_perform", "UInt", hCurlEasy)
MsgBox % CURL_ERROR
Progress, Off
CloseHandle(hFile)
VarSetCapacity(CURLINFO_SPEED_DOWNLOAD, 8)
DllCall("libcurl-4\curl_easy_getinfo", "UInt", hCurlEasy, "UInt", 0x300000 + 9, "UInt", &CURLINFO_SPEED_DOWNLOAD, "Cdecl")
VarSetCapacity(CURLINFO_TOTAL_TIME, 8)
DllCall("libcurl-4\curl_easy_getinfo", "UInt", hCurlEasy, "UInt", 0x300000 + 3, "UInt", &CURLINFO_TOTAL_TIME, "Cdecl")
MsgBox % "Average download speed: " . Round(NumGet(CURLINFO_SPEED_DOWNLOAD, 0, "Double"), 0) . " bytes\s`nTransfer time: " . Round(NumGet(CURLINFO_TOTAL_TIME, 0, "Double"), 0) . " seconds"
DllCall("libcurl-4\curl_easy_cleanup", "UInt", hCurlEasy)
DllCall("FreeLibrary", "UInt", hModule)
Curl_ProgressFunction(clientp, dltotal_l, dltotal_h, dlnow_l, dlnow_h, ultotal_l, ultotal_h, ulnow_l, ulnow_h)
{
VarSetCapacity(dltotal, 8, 0)
NumPut(dltotal_l, dltotal, 0), NumPut(dltotal_h, dltotal, 4)
VarSetCapacity(dlnow, 8, 0)
NumPut(dlnow_l, dlnow, 0), NumPut(dlnow_h, dlnow, 4)
KBTotal := Round((NumGet(dltotal, 0, "Double") / 1024), 2)
KBNow := Round((NumGet(dlnow, 0, "Double") / 1024), 2)
Percent := Round((NumGet(dlnow, 0, "Double") / NumGet(dltotal, 0, "Double") * 100), 2)
Progress, %Percent%, %KBNow% of %KBTotal% KB (%Percent% `%)
Return 0
}
Curl_WriteFunction(pBuffer, size, nitems, pOutStream)
{
global hFile
WriteFile(hFile, pBuffer, size*nitems)
return size*nitems
}
Curl_Version()
{
Return DllCall("MulDiv", "Int", DllCall("libcurl-4\curl_version"), "Int",1, "Int",1, "str")
}
Edit1: Added example of curl_easy_getinfo