ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Communication / FTP functions
  • Reminder about the FTP protocol
  • FTP commands
  • Example: Getting a TEST file located in the AAA library of an AS/400:
  • Use conditions
  • Required permissions
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
Sends a specific FTP command to a server.
Caution: This function is not available in the following connection modes:
  • FTPIS: FTP secured using SSL with implicit encryption.
  • FTPES: FTP secured using SSL with explicit encryption.
  • SFTP: FTP secured using an SSH tunnel.
PHP Sends a specific FTP SITE command to a server.
New in SaaS
A new syntax for manipulating variables of type ftpConnection is available from WINDEV Suite SaaS 2025 - Update 2.
WINDEVWEBDEV - Server codeReports and QueriesAndroidAndroid Widget JavaUser code (UMC)Ajax
// Connect the current computer to the FTP server
ConnectionNumber = FTPConnect("192.54.12.8")
// Request from the server system
IF FTPCommand(ConnectionNumber, "SYST", Response) = True THEN
	Info("Server system information: " + CR + Response)
ELSE
	Info("The server does not support the SYST command." + ...
		"No information about the server system is available")
END
// Ask for the list of files found in the current directory
IF FTPCommand(ConnectionNumber, "LIST", Response, MyList) = True THEN
	// The list of files found in the current directory on the server is as follows
	Info("Files in the current directory on the server: " + CR + MyList)
END
PHP
// Connect the current computer to the FTP server
ConnectionNumber = FTPConnect("192.54.12.8")
// Create a group named TestGroup
IF FTPCommand(ConnectionNumber, "ADDGROUP TestGroup") = True THEN
	Info("The TestGroup group was created")
ELSE
	Info("The server does not accept the ADDGROUP command.")
END
// Ask for the list of files found in the current directory
IF FTPCommand(ConnectionNumber, "EXEC ls > list.txt") = True THEN
	// The list of files found in the current directory on the server is stored in list.txt
	Info("The list of file in the current" + ...
		  " directory on the server is stored in List.txt")
END
New in SaaS
WINDEVWEBDEV - Server codeReports and QueriesAndroidAndroid Widget JavaUser code (UMC)Ajax
// Syntax not available in PHP
// Connect the current computer to the FTP server
MyFTPConnection is ftpConnection
MyFTPConnection.Server = "192.54.12.8"
FTPConnect(MyFTPConnection)

IF FTPCommand(MyFTPConnection, "SYST", Response) = True THEN
	Info("Server system information: " + CR + Response)
ELSE
	Info("The server does not support the SYST command." + ...
		"No information about the server system is available")
END
// Ask for the list of files found in the current directory
IF FTPCommand(MyFTPConnection, "LIST", Response, MyList) = True THEN
	// The list of files found in the current directory on the server is as follows
	Info("Files in the current directory on the server: " + CR + MyList)
END
Syntax
WINDEVWEBDEV - Server codeWINDEV MobileReports and QueriesAndroidAndroid Widget JavaUser code (UMC)Ajax

Sending a specific FTP command to a server Hide the details

<Result> = FTPCommand(<FTP connection> , <FTP command> [, <Server response> [, <Command result> [, <Transfer mode> [, <Data to send>]]]])
<Result>: Boolean
  • True if the command was run,
  • False if a problem occurred.
<FTP connection>: Integer or ftpConnection variable
<FTP command>: Character string
FTP command sent to the server.
<Server response>: Optional character string
String variable containing the server response for the specified FTP command. This parameter enables you to get the server response on the command channel (the command channel allows error or success messages to be received).
<Command result>: Optional ANSI string
ANSI string variable containing the data corresponding to the result of the specified FTP command. This result is returned by the server on the data channel.
Note: If this parameter is specified, FTPCommand prevents any further actions until the result is received. More specifically, if the command does not expect a result through the data channel, the client is locked indefinitely. For more details, see the RFC959 specification.
<Transfer mode>: Optional Integer constant
Transfer mode used:
ftpASCIIModeTransfer performed in ASCII mode. This mode is used to transfer files between different operating systems, e.g. UNIX to Windows. The file is delivered in the ASCII format used by the receiving system.
ftpBinaryMode
(Default value)
Transfer in binary mode. In this mode, the file received is strictly identical to the file sent.
<Data to send>: Optional character string
Data associated with the FTP command that will be sent to the FTP server. This data is sent through the data channel.
PHP

Sending an FTP SITE command to a server Hide the details

<Result> = FTPCommand(<Connection ID> , <FTP command>)
<Result>: Boolean
  • True if the command was run,
  • False if a problem occurred.
<Connection ID>: Variant
Connection identifier, returned by FTPConnect.
<FTP command>: Character string
FTP command sent to the server.
Remarks

Reminder about the FTP protocol

This protocol uses 2 communication channels:
  • A command channel, which allows sending commands and receiving error or success messages.
  • A data channel, which is used to transmit the data associated with the command.

FTP commands

All the commands that can be used on an FTP server are found in the RFC989 specification. This document is available on the Internet (simply search for the RFC989 reference).
Common example: Uploading and downloading files with FTPCommand
1. Downloading files:
Response, ResData are strings
FTPCommand(<Connection identifier>, ...
"RETR" + <Name file server>, ...
Response, ResData, <Transfer mode>)
// ResData contains the file
2. Uploading files:
Response, ResData, DataResult are strings
// ResData contains the file to upload
FTPCommand(<Connection identifier>,...
"STOR " + <Name File server>, ...
Response, DataResult, <Transfer mode>, ResData)

Example: Getting a TEST file located in the AAA library of an AS/400:

Response, ResData are strings 
FTPID = FTPConnect("as400", "login", "PWD")
FTPCommand(FTPID,"RETR " + "AAA/TEST", Response, ResData)
// ResData contains the file
fSaveText("C:\Tmp\test", ResData)
WINDEVWEBDEV - Server codeReports and QueriesWindowsAndroidAndroid Widget JavaUser code (UMC)Ajax

Use conditions

FTPCommand is available only if Internet Explorer 5 (or later) is installed on the computer of the FTP client.
AndroidAndroid Widget

Required permissions

This function changes the permissions required by the application.
Required permission: INTERNET
This permission allows the applications to open the network sockets.
Business / UI classification: Business Logic
Component: wd300com.dll
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 04/30/2025

Send a report | Local help