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 found in the AAA library of an AS/400:
  • Use conditions
  • Required permissions
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
FTPCommand (Function)
In french: FTPCommande
Sends a specific FTP command to a server.
Caution: This function is not available during a connection in mode:
  • FTPIS: FTP secured according to the SSL protocol with implicit encryption.
  • FTPES: FTP secured according to the SSL protocol with explicit encryption.
  • SFTP: FTP secured by a SSH channel.
PHP Sends a specific FTP SITE command to a server.
WINDEVWEBDEV - Server codeReports and QueriesAndroidAndroid Widget JavaUser code (UMC)Ajax
// Connect the current computer to the FTP server
ConnectionNum = FTPConnect("192.54.12.8")
// Request from the server system
IF FTPCommand(ConnectionNum, "SYST", Response) = True THEN
Info("Information about the server system: " + 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(ConnectionNum, "LIST", Response, MyList) = True THEN
// The list of files found in the current directory on the server is as follows
Info("List of files found in the current directory on the server: " + CR + MyList)
END
WEBDEV - Server codePHP
// Connect the current computer to the FTP server
ConnectionNum = FTPConnect("192.54.12.8")
// Create a group named TestGroup
IF FTPCommand(ConnectionNum, "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(ConnectionNum, "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
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(<Connection identifier> , <FTP command> [, <Server response> [, <Result of command> [, <Transfer mode> [, <Data to send>]]]])
<Result>: Boolean
  • True if the command was run,
  • False if a problem occurred.
<Connection identifier>: Integer
Connection identifier, returned by FTPConnect.
<FTP command>: Character string
FTP command sent to the server.
<Server response>: Optional character string
Character string variable containing the server response for the specified FTP command. This parameter enables you to get the server response on the connection channel (the connection channel allows error or success messages to be received).
<Result of command>: Optional ANSI character string
ANSI Character 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.
Caution: If this parameter is specified, FTPCommand locks the computer until a 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 data between two different types of operating systems, from UNIX to Windows for example: the transferred file is changed into the ASCII format of destination system.
ftpBinaryMode
(Default value)
Transfer performed in binary mode: The file is strictly identical between the sending and the receiving.
<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.
WEBDEV - Server codePHP

Sending an FTP SITE command to a server Hide the details

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

Reminder about the FTP protocol

This protocol is using 2 communication channels:
  • A command channel: is used to send commands and to receive error or success messages,
  • A data channel used to transfer 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 (use a search engine and search for the RFC959 reference).
Some standard examples: 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 found 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

The call to this function modifies the permissions required by the application.
Required permission : INTERNET
This permission allows the applications to open the network sockets.
Component: wd290com.dll
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 05/26/2022

Send a report | Local help