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:

  • ConnectFtpClient performs a connection to the FTP server (as specified in previous parameters).

  • DisconnectFtpClient performs the disconnection from the FTP server.

  • DownloadItem performs the download of the remote item (file/folder) contained in the parameter remoteItemPath inside the localFolderPath folder. Through the overwriteItemIfExists parameter it is possible to establish if any existing files should be overwritten or not.

  • UploadItem uploads the local item (file/folder) contained in the localItemPath parameter to the remoteFolderPath folder. Through the overwriteItemIfExists parameter 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 ExtensionFilter property 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 ‘.’).

  • ShowHiddenFiles indicates whether you want to show hidden files or not (does not apply on remote filesystems of Windows FTP servers).

  • StartLocalFilesystemPath indicates the starting folder to browse the local filesystem.

  • AccessFullFilesystem lets 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 AccessFullFilesystem is enabled it is also possible to show the network drives mapped via AccessLocalNetworkDrives.

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 configuration allows changing the configuration parameters of the FTP client. The OverwriteExistingItems switch defines whether an existing file has to be overwritten or not.

  • Transfer files shows how to connect/disconnect the FTP client via ConnectFTPClient/DisconnectFTPClient methods and how to download/upload via DownloadItem and UploadItem methods.

  • Periodic backup allows you to enable periodic downloading of a given file, via the PeriodicActionLogic script. The script is set with Period to 30 seconds and Action set with DownloadItem.

Download the example here.