libcurl.pbi

Share your advanced PureBasic knowledge/code with the community.
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

libcurl.pbi

Post by infratec »

Since there were many places with different links, I decided to make an own thread for libcurl.pbi.

The download link will provide always the latest version of:

libcurl.pbi

PB replacement with Timeout feature:
HTTPRequestI.pbi

Examples:
Asynchronous.pb
EMailWithBinaryFileAttachment.pb
EMailWithFileAttachment.pb
FTPS_download.pb
FTPS_upload.pb
GetCertInfo.pb
IMAP.pbi
NextCloud.pbi
OutLookEMail.pb
PaperlessNgx.pbi
pop3.pbi
scp_to.pb
SFTP_get.pb
SFTP_upload.pb
SFTP_uploadresume.pb
SMTPS.pb

https://www.von-der-salierburg.de/downl ... eBasic.zip

Usefull links:
https://curl.se/libcurl/c/libcurl.html
https://curl.se/windows/

At the moment (PB 6.10 beta 7) the windows version includes libcurl V7.68 and supports the following protocols:
--- LibCurl Info ---
Version: 7.68.0
Host: i386-pc-win32
SSL: Schannel

Protocols:
ftp
ftps
http
https
smtp
smtps
--- LibCurl Info ---
My included dll supports the following protocols:
--- LibCurl Info ---
Version: 8.6.0
Host: i686-w64-mingw32
SSL: LibreSSL/3.8.2
Libz: 1.3.1
libSSH: libssh2/1.11.0

Protocols:
dict
file
ftp
ftps
gopher
gophers
http
https
imap
imaps
ldap
ldaps
mqtt
pop3
pop3s
rtsp
scp
sftp
smb
smbs
smtp
smtps
telnet
tftp
ws
wss

Features:
alt-svc
AsynchDNS
brotli
HSTS
HTTP2
HTTP3
HTTPS-proxy
IDN
IPv6
Largefile
libz
NTLM
PSL
SSL
threadsafe
UnixSockets
zstd
--- LibCurl Info ---
Last edited by infratec on Sun Mar 03, 2024 1:55 pm, edited 26 times in total.
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: libcurl.pbi

Post by infratec »

GetCertInfo()
works now as it should.
The structure for certinfo was wrong.

Changed all examples to use the new defines:

Code: Select all

#LibCurl_ExternalDLL
#LibCurl_ExternalStaticLib
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: libcurl.pbi

Post by infratec »

Updated libcurl to 7.86.0

Added LibCurl_Info() to libcurl.pbi.
Now you can see informations about version and included protocols by simply call LibCurl_Info().
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: libcurl.pbi

Post by infratec »

infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: libcurl.pbi

Post by infratec »

Fixed a bug:

The last parameter of curl_easy_setopt() needs to be a .q :!:

I found this bug during I wrote NextCloud.pbi.
The upload was not possible without .q

At the moment NextCloud.pbi contains:

Code: Select all

Procedure.i NextCloud_GetShares(URL$, Username$, Password$, List ShareList$())
Procedure.i NextCloud_FileExists(URL$, Username$, Password$, File$)
Procedure.i NextCloud_CreateFolder(URL$, Username$, Password$, Path$)
Procedure.i NextCloud_UploadFile(URL$, Username$, Password$, LocalFile$, RemoteFile$)
Procedure$ NextCloud_CreateShareLink(URL$, Username$, Password$, RemoteFile$, SharePassword$=#Null$)
Procedure.i NextCloud_CopyFile(URL$, Username$, Password$, RemoteSource$, RemoteDestination$, OverwriteIfExists.i=#False)
And a demo.
Last edited by infratec on Sun Jul 09, 2023 8:32 pm, edited 1 time in total.
Joubarbe
Enthusiast
Enthusiast
Posts: 555
Joined: Wed Sep 18, 2013 11:54 am
Location: France

Re: libcurl.pbi

Post by Joubarbe »

Thank you for that! The NextCloud library is definitely interesting for me!
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: libcurl.pbi

Post by infratec »

I added new procedures to NextCloud.pbi:

Code: Select all

Procedure.i NextCloud_GetShares(URL$, Username$, Password$, List ShareList$())
Procedure.i NextCloud_FileExists(URL$, Username$, Password$, File$)
Procedure.i NextCloud_CreateFolder(URL$, Username$, Password$, Path$)
Procedure.i NextCloud_UploadMemoryToFile(URL$, Username$, Password$, *Memory, Size.i, RemoteFile$)
Procedure.i NextCloud_UploadFile(URL$, Username$, Password$, LocalFile$, RemoteFile$)
Procedure.i NextCloud_DeleteFileOrFolder(URL$, Username$, Password$, File$)
Procedure.i NextCloud_DownloadFile(URL$, Username$, Password$, FileToDownload$, TargetFile$)
Procedure.s NextCloud_CreateShareLink(URL$, Username$, Password$, RemoteFile$, SharePassword$=#Null$)
Procedure.i NextCloud_CopyFile(URL$, Username$, Password$, RemoteSource$, RemoteDestination$, OverwriteIfExists.i=#False)
NextCloud_UploadFile() reads now from the file and don't need additional RAM.
I did this, because uploading a DVD file is to large for the internal RAM.
But I added NextCloud_UploadMemoryToFile() where you can directly upload *Memory to a file.

I also changed the name of the 2 callback procedures to reflect the CURL_OPTION parameter names.
Last edited by infratec on Sun Jul 09, 2023 8:32 pm, edited 1 time in total.
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: libcurl.pbi

Post by infratec »

Changed NextCloud.pbi a bit:

Code: Select all

Procedure.i NextCloud_GetShares(URL$, Username$, Password$, List ShareList$())
Procedure.i NextCloud_ExistsFileOrFolder(URL$, Username$, Password$, File$)
Procedure.i NextCloud_CreateFolder(URL$, Username$, Password$, Path$)
Procedure.i NextCloud_UploadMemoryToFile(URL$, Username$, Password$, *Memory, Size.i, RemoteFile$)
Procedure.i NextCloud_UploadFile(URL$, Username$, Password$, LocalFile$, RemoteFile$)
Procedure.i NextCloud_DeleteFileOrFolder(URL$, Username$, Password$, File$)
Procedure.i NextCloud_DownloadFile(URL$, Username$, Password$, FileToDownload$, TargetFile$)
Procedure.s NextCloud_CreateShareLink(URL$, Username$, Password$, RemoteFile$, SharePassword$=#Null$)
Procedure.i NextCloud_CopyFile(URL$, Username$, Password$, RemoteSource$, RemoteDestination$, OverwriteIfExists.i=#False)
I also extended the Demo at the end of the code.
Last edited by infratec on Sun Jul 09, 2023 8:32 pm, edited 1 time in total.
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: libcurl.pbi

Post by infratec »

I forgot to add curl_mime_name() :oops:
This is fixed now. It is needed for multipart forms.

To show an example I added PaperlessNgx.pbi:

Code: Select all

Procedure.i PaperlessNgx_UploadFile(URL$, Username$, Password$, File$, List TagList.PaperlessNgx_IdNameResultList_Structure(), *Correspondent.PaperlessNgx_IdNameResultList_Structure=#Null, *DocumentType.PaperlessNgx_IdNameResultList_Structure=#Null)
Last edited by infratec on Sun Jul 09, 2023 8:32 pm, edited 1 time in total.
loulou2522
Enthusiast
Enthusiast
Posts: 495
Joined: Tue Oct 14, 2014 12:09 pm

Re: libcurl.pbi

Post by loulou2522 »

HI infratec
The link in first page isn't good or downloading libcurl.zip , it retrun on a dog site. Can you see. THanks
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: libcurl.pbi

Post by infratec »

Ups... was a problem of capital letters.
I fixed the link above.
loulou2522
Enthusiast
Enthusiast
Posts: 495
Joined: Tue Oct 14, 2014 12:09 pm

Re: libcurl.pbi

Post by loulou2522 »

Thanks Unfratec,
That's work well for downloading. I will try now with example
loulou2522
Enthusiast
Enthusiast
Posts: 495
Joined: Tue Oct 14, 2014 12:09 pm

Re: libcurl.pbi

Post by loulou2522 »

Hello infratec,
I use you outlookemail.pb and i want to embed an image in the text of the mail . How can i proramm it ?
Thanks in advance
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: libcurl.pbi

Post by infratec »

1. This question is not libcurl related.
2. I don't use outlook, so I can test nothing.

Write an e-mail in outlook with embedded picture, send it to yourself and inspect the source code of the e-mail.

Maybe this is also useful:
https://stackoverflow.com/questions/670 ... html-email

But it looks that outlook does not accept inline Base64 images (which is the easiest way).
So you need the cid way with additional boundary and the binary image.
And even then outlook may not show it depending if the sender is trusted or not.
loulou2522
Enthusiast
Enthusiast
Posts: 495
Joined: Tue Oct 14, 2014 12:09 pm

Re: libcurl.pbi

Post by loulou2522 »

In fact i don't use outlook to send mail i use my own provider free.fr and curlib but i have modify your outlook.mb like following
#MailServer = "smtp.free.fr:587"

#FROM = "<xxxx@free.fr>"
#To = "<xxx@sxxxxxx>"

#SMTP_User = "xxx@free.fr"
#SMTP_Password = "xxxxx"
I can send outline attachements with
*part = curl_mime_addpart(*mime)
curl_mime_filedata(*part, "index.php")
Post Reply