Makers Blog Archive

Crosscompile Guide: cURL Library for FTP / SMTP

Oliver PLCnext Team 09 August 2018 min. read
626 views 0 comments

libcurl – the multiprotocol file transfer library

libcurl is a free and easy-to-use client-side URL transfer library, supporting DICTFILEFTPFTPSGopherHTTPHTTPSIMAPIMAPSLDAPLDAPSPOP3POP3SRTMPRTSPSCPSFTPSMTPSMTPSTelnet and TFTP.

libcurl supports SSL certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, cookies, user + password authentication (Basic, Digest, NTLM, Negotiate, Kerberos), 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, macOS 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.

cURL and libcurl are licensed under a MIT/X derivate license, see License information

Why to build it

libcurl is already included in AXC F 2152 Firmware 1.1.0 with some features:

admin@axcf2152:~$ curl --version
curl 7.50.1 (arm-pxc-linux-gnueabi) libcurl/7.50.1 GnuTLS/3.5.3 zlib/1.2.8
Protocols: file ftp ftps http https 
Features: IPv6 Largefile NTLM NTLM_WB SSL libz TLS-SRP UnixSockets 

But there’s a lot more features and protocols that can be added.

Here’s how you build it with these features additional included:

OpenSSLTLS (https) support
zlibAutomatic “deflate” decompression

How to build it

  1. download latest source by git clone https://github.com/curl/curl.git
  2. execute source /opt/pxc/current/environment* to load PLCnext environment variables. (SDK path is usually /opt/pxc/2.2.1/)
  3. change to the curl directory: cd curl-master/
  4. execute autoreconf -i to go into developer mode
  5. execute autoconf configure.ac to generate configure script
  6. execute ./configure $CONFIGURE_FLAGS --prefix=YourInstallDirectory to generate files for PLCnext toolchain; Install folder example: --prefix=/home/XXX/Installconfigure: Configured to build curl/libcurl: curl version: 7.60.0-DEV Host setup: arm-pxc-linux-gnueabi Install prefix: /home/XXX/Install Compiler: arm-pxc-linux-gnueabi-gcc -march=armv7-a -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 --sysroot=/home/ima/PLCnext/SDK/sysroots/cortexa9t2hf-neon-pxc-linux-gnueabi SSL support: enabled (OpenSSL) SSH support: no (--with-libssh2) zlib support: enabled brotli support: no (--with-brotli) GSS-API support: no (--with-gssapi) TLS-SRP support: enabled resolver: POSIX threaded IPv6 support: enabled Unix sockets support: enabled IDN support: no (--with-{libidn2,winidn}) Build libcurl: Shared=yes, Static=yes Built-in manual: enabled --libcurl option: enabled (--disable-libcurl-option) Verbose errors: enabled (--disable-verbose) SSPI support: no (--enable-sspi) ca cert bundle: no ca cert path: no ca fallback: no LDAP support: no (--enable-ldap / --with-ldap-lib / --with-lber-lib) LDAPS support: no (--enable-ldaps) RTSP support: enabled RTMP support: no (--with-librtmp) metalink support: no (--with-libmetalink) PSL support: no (libpsl not found) HTTP2 support: disabled (--with-nghttp2) Protocols: DICT FILE FTP FTPS GOPHER HTTP HTTPS IMAP IMAPS POP3 POP3S RTSP SMB SMBS SMTP SMTPS TELNET TFTP
  7. execute make to compile
  8. execute make install to install binaries to –prefix=folder

TO DO:

Include additional feature support, if necessary

OpenLDAPLDAP support
mbed TLSTLS (https) support
heimdalSupport for GSS-API can be provided by the heimdal package and is used to provide the Kerberos and SPNEGO authentication in libcurl.
MIT KerberosThe MIT Kerberos package is also a GSS-API library which can be used to provide support for the Kerberos and SPNEGO authentication in libcurl.
nghttp2http2 support
c-aresAsynchronous name resolves
libidnPerforming the proper IDNA encodings for international domain names to work.
GnuTLSTLS (https) support
NSSTLS (https) support
wolfSSLTLS (https) support
libssh2SCP and SFTP support
libmetalinkMetalink support

Try to build with everything

Note: Will fail without compiling the dependencies first.

./configure $CONFIGURE_FLAGS --prefix=/home/ima/Install/ --with-libssh2 --with-brotli --with-gssapi --with-libidn2 --enable-sspi --enable-ldap --enable-ldaps --with-librtmp --with-libmetalink --with-nghttp2

For SCP and SFTP support --with-libssh2

  1. clone libssh2 from git:
    git clone https://github.com/libssh2/libssh2.git
  2. compile libssh2source /opt/pxc/current/environment* ./buildconf ./configure $CONFIGURE_FLAGS --prefix=/home/XXX/Install/ make make install
  3. Compile cURL and add libssh support./configure $CONFIGURE_FLAGS --prefix=/home/XXX/Install/ --with-libssh2=/home/XXX/Install/ make && make install... SSH support: enabled (libSSH2) zlib support: enabled ... PSL support: no (libpsl not found) HTTP2 support: disabled (--with-nghttp2) Protocols: DICT FILE FTP FTPS GOPHER HTTP HTTPS IMAP IMAPS POP3 POP3S RTSP SCP SFTP SMB SMBS SMTP SMTPS TELNET TFTP

cURL after our own compile

  1. Copy the the contents from /home/XXX/Install/ to the PLC at /usr/local/
  2. Execute sudo ldconfig
admin@axcf2152:/usr/local/bin# ./curl --version
curl 7.61.1-DEV (arm-pxc-linux-gnueabi) libcurl/7.61.1-DEV OpenSSL/1.0.2j zlib/1.2.11 libssh2/1.8.1_DEV
Release-Date: [unreleased]
Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp 
Features: AsynchDNS IPv6 Largefile NTLM NTLM_WB SSL libz TLS-SRP UnixSockets HTTPS-proxy 

Setting up a PLCnext project with cURL

  1. Create an Eclipse® C++ project
  2. Include headers in project properties:
    "/prefix/includes"
  3. Include libraries in project properties:
    add "curl"
  4. Include libraries path in project properties: add the path "/prefix/lib"
  5. Include cURL header #include "curl/curl.h" into project and compile to test if it compiles fine

Where to find the properties:

  1. right-click the project
  2. choose “Properties” -> “C/C++ Build” -> “Settings”
  3. go to “Cross G++ Compiler” -> “Includes”
  4. go to “Cross G++ Linker” -> “Libraries”

Notes about the APIs

  • Check out this page about the [cURL API] (https://curl.haxx.se/libcurl/c/)
  • There are two APIs included: an “Easy” one and an “Multi”-ASYNC API
  • Watch out!
    Even in the multi API, some functions are blocking and might pose a danger to your RealTime execution.

Note:

The Makers Blog shows applications and user stories of community members that are not tested or reviewed by Phoenix Contact. Use them at your own risk.

Discussion

Please login/register to comment

Login/Register

Leave a Reply

Newsletter
Never miss a new article
Sign up for the newsletter
Never miss news about PLCnext Technology
Get interesting content via newsletter four times a year
Receive exclusive information before all other users