FTP Client¶
In the UNIQO Template Library there are a runtime script and a widget that allow you to make connections to FTP servers.
Note
FTPS connections are not currently supported.
The following NuGet package is required:
To install the NuGet packages see Add NuGet packages.
It is recommended to use stable versions of the packages.
FTP client script
FTPClientLogic is a runtime script that exposes OPCUA methods to perform file listing/transfer to/from an FTP server.
Impostazioni
The configurable parameters are as follows:
FtpServerIPAddress: IP address of the FTP server.FtpServerPort: FTP server port.FtpServerUsername: username of the user used to authenticate on the FTP server.FtpServerUserPassword: password of the user used to authenticate on the FTP server.OverwriteFileIfExists: determines whether any existing files must be overwritten or not.
The following parameters expose instead the internal state of the client (to be used as read-only):
FtpClientIsRunning: indicates if the client is currently connected to an FTP server.FtpClientOperationInProgress: indicates if the client is executing some operations (file list/transfer).
The exposed methods are the following:
ConnectFtpClientperforms a connection to the FTP server (as specified in previous parameters).DisconnectFtpClientperforms the disconnection from the FTP server.DownloadItemperforms the download of the remote item (file/folder) contained in the parameterremoteItemPathinside thelocalFolderPathfolder. Through theoverwriteItemIfExistsparameter it is possible to establish if any existing files should be overwritten or not.UploadItemuploads the local item (file/folder) contained in thelocalItemPathparameter to theremoteFolderPathfolder. Through theoverwriteItemIfExistsparameter it is possible to determine if any existing files should be overwritten or not.
FTP client widget
FTPClientWidget allows you to list/transfer files to/from an FTP server via a graphical interface.
Impostazioni
The configurable parameters are as follows:
FtpServerIPAddress: IP address of the FTP server.FtpServerPort: FTP server port.Username: username of the user to be used to authenticate on the FTP server.Password: password of the user to be used to authenticate on the FTP server.In the
ExtensionFilterproperty it is possible to set one or more filters to view only certain files according to their extension. In case more than one extension is specified, it is necessary to separate them with ‘;’. For example, set ‘.txt;.csv’ to display only files with extension .txt and .csv. By default all files are shown (via ‘.’).ShowHiddenFilesindicates whether you want to show hidden files or not (does not apply on remote filesystems of Windows FTP servers).StartLocalFilesystemPathindicates the starting folder to browse the local filesystem.AccessFullFilesystemlets you decide whether to allow full filesystem browsing. This option is only supported for Windows and Debian systems. In these cases you can browse from the root of the disks on Windows and from the ‘/’ (root) folder on Debian.On Windows, when
AccessFullFilesystemis enabled it is also possible to show the network drives mapped viaAccessLocalNetworkDrives.
Trasferimento periodico di un file via FTP
By combining FTPClientLogic and PeriodicActionLogic runtime scripts, it is possible to automate the transfer (upload/download) of files/folders in a periodic and non-interactive manner. It can be useful in case you need to automate file/folder transfers between different devices.
For correct execution of the example the following configuration of an FTP server is required:
create the folder ‘C:/FtpServer’ and inside it a file called ‘myDocument.txt’.
set ‘C:/FtpServer’ as the starting folder on the FTP server.
configure the FTP server parameters (e.g. IP address, port, authorized users).
start the FTP server.
To use the FTP server already present in the template library see FTPServer.
Then, you have to configure the connection parameters to the FTP server on the script FTPClientLogic.
The files/folders to be transferred are already configured through the objects FileTransferDownload and FileTransferUpload.
The pages in the project are the following:
FTP client configurationallows changing the configuration parameters of the FTP client. TheOverwriteExistingItemsswitch defines whether an existing file has to be overwritten or not.Transfer filesshows how to connect/disconnect the FTP client viaConnectFTPClient/DisconnectFTPClientmethods and how to download/upload viaDownloadItemandUploadItemmethods.Periodic backupallows you to enable periodic downloading of a given file, via thePeriodicActionLogicscript. The script is set withPeriodto 30 seconds andActionset withDownloadItem.
Download the example here.