ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

This content has been translated automatically.  Click here  to view the French version.
Help / WLanguage / WLanguage functions / Communication / FTP functions
  • Security error in a secure FTPS connection
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
Connects the current computer to an FTP server (File Transfer Protocol).
WINDEVWindows The available secure connection modes are as follows:
  • FTPS: SSL-secured FTP with implicit encryption.
  • FTPES: SSL-secured FTP with explicit encryption.
  • SFTP: FTP secured by an SSH tunnel.
// Connect the current computer to the FTP server
ResConnect = FTPConnect("192.54.12.8")
Syntax
<Result> = FTPConnect(<Server> [, <User name> [, <Password> [, <Port number> [, <Type of connection> [, <Connection timeout> [, <Private key> [, <Key password>]]]]]]])
<Result>: Integer
  • Connection ID,
  • 0 during the first connection.
  • -1 if an error occurred. The details of the error are returned by ErrorInfo with the errCode or errMessage constant.
    If an identification error occurs, ErrorInfo with the errCode constant returns the ftpErrorAuthentication constant.
<Server>: Character string
Name of FTP server ("ftp.cdrom.com" for example) or IP address of FTP server ("192.54.12.8" for example).
WINDEVWindows This parameter is used to define the protocol used:
  • if the server name starts with "ftp://", the connection is established in non-secure mode.
  • if the server name starts with "ftps://", the connection is established in secure mode according to the FTPS protocol (FTP secured by SSL with implicit encryption).
  • if the server name starts with "ftpes://", the connection is established in secure mode according to the FTPES protocol (FTP secured by SSL with explicit encryption).
  • if the server name starts with "sftp://", the connection is established in secure mode via a SSH channel according to the SFTP protocol.
<User name>: Optional character string
  • Name of user attempting to perform a named connection (user authentication on FTP server). This parameter is given by the administrator of FTP server.
  • Empty string ("") to perform an anonymous connection.
<Password>: Optional character string
User password: identifies the user on the FTP server. This parameter is given by the administrator of FTP server.
This password corresponds to:
  • the specified <Password> if this parameter is not an empty string (""),
  • the email address of the user if <Username> is not specified or it is equal to an empty string (""),
  • an empty string ("") if this parameter is not specified and if <Username> does not correspond to an empty string ("").
Note: If the password contains special characters, it may be necessary to convert it to UTF8 using the StringToUTF8 function.
<Port number>: Optional integer
Number of the port on which the server will be run. This parameter is given by the administrator of FTP server.
By default:
  • for a non-secure connection, this port is port 21.
  • WINDEVWindows for a secure connection in FTPS mode, this port is port 990.
  • WINDEVWindows for a secure connection in FTPES mode, this port is port 21.
  • WINDEVWindows for a secure connection in SFTP mode, this port is port 22.
<Type of connection>: Optional Integer constant
Type of connection to perform:
ftpActiveMode (or False for compatibility)Active connection to the FTP server.
When transferring files, the client starts the transfer. This type of connection may be refused by some protected FTP servers.
ftpExtendedPassiveModeExtended passive connection to the FTP server (EPSV mode).
When transferring files, the server takes the initiative for the transfer. This type of connection is used to step over some "firewalls".
If the server does not support the extended passive mode (the FEAT command is sent to the server to find out the capacity), the connection is crippled in simple passive mode.
Limitations:
  • This mode is not supported when using the Windows "wininet" module (see function FTPConfigure): the connection is made in mode ftpModePassif.
  • Java Constant not available.
ftpPassiveMode (or True for compatibility)
(Default value)
Passive connection to the FTP server (PASV mode).
When transferring files, the server takes the initiative for the transfer. This type of connection is used to step over some "firewalls".
Note: If the connection to the server is in IPV6, then the connection will be made in extended passive mode (because passive mode does not support IPV6)..
ftpPassiveModeIgnoreIPPassive connection to the FTP server (PASV mode).
When transferring files in passive mode, the server sets the port and IP address for data transfer. With this parameter, only the port is taken into account. The IP address is ignored.
This type of connection allows the use of FTP servers that return non-routable IP addresses but are reachable via the connection IP address
Limitations:
  • This mode is not supported when using the Windows "wininet" module (see function FTPConfigure): the connection is made in mode ftpModePassif.
<Connection timeout>: Optional integer or optional Duration
Number of seconds after which the request for connecting to the FTP server is canceled (20 by default). This timeout applies to all FTP operations performed on this connection. If no response is received from the server during the specified <Connection timeout>, FTPConnect returns -1.
Note: This parameter can correspond to:
  • an integer corresponding to the number of seconds,
  • a Duration variable,
  • the duration in a readable format (e.g., '1s').
<Private key>: Optional character string
WINDEVWindows Name and path of file corresponding to the private key used during a connection in SFTP mode. This file must have been generated in OpenSSH format.
If this parameter is not specified, the secure connection uses an authentication by <Username>/<Password>.
<Key password>: Optional ANSI character string
WINDEVWindows Password of file containing the private key used during a connection in SFTP mode.
If Unicode is used for executing strings ("Unicode" tab of current configuration), the password must not be enclosed in quotation marks. It must be in a string variable declared in ANSI format.
If this parameter is not specified, the secure connection uses an authentication by <Username>/<Password>.
Remarks
WINDEVWindowsLinux

Security error in a secure FTPS connection

During a secure transaction, the function may fail due to security errors:
  • invalid certificate or certificate coming from an unknown company.
  • site name found in the certificate not corresponding to a server.
  • invalid or expired certificate date.
You have the ability to connect while ignoring these errors. To do so, use the FTP.IgnoreError variable:
Value of FTP.IgnoreError
(these values can be combined)
Description
ftpIgnoreInvalidCertificateThe certificate is ignored.
ftpIgnoreExpiredCertificateThe certificate date is ignored.
ftpIgnoreInvalidCertificateNameThe site name specified in the certificate is ignored.
ftpIgnoreRevocationThe certificate revocation is ignored.
// Example for error management

xnum is int
FTP.IgnoreError = ftpIgnoreExpiredCertificate + ftpIgnoreInvalidCertificate + ...
	ftpIgnoreInvalidCertificateName + ftpIgnoreRevocation
xnum = FTPConnect("ftpes://My_Server_IP", "My_User", "My_Password", 21, True)
IF xnum =-1  THEN
       Info(ErrorInfo(errMessage))
ELSE
       Info("OK")
END
Related Examples:
The FTP functions Unit examples (WINDEV): The FTP functions
[ + ] Using the main FTP functions of WINDEV:
- Connect to a FTP server
- List the files and directories found on the FTP server
- Retrieve the files found on the FTP server
- Disconnect from a FTP server
WD FTP File Transfer Complete examples (WINDEV): WD FTP File Transfer
[ + ] WD FTP file transfer

This example is a full FTP client allowing you to store several FTP servers. Then, you have the ability to perform multi-file transfers from the local computer to the server or from the FTP server to the local computer. To do so, we are using the standard functions of WLanguage (FTPConnect, etc...)
Component: wd300com.dll
Minimum version required
  • Version 9
This page is also available for…
Comments
Video FtpConnect
https://youtu.be/P3cQ9XJDGYk
amarildo
26 Oct. 2018

Last update: 10/17/2024

Send a report | Local help