Y_CO_FTP_SendFile
Parameters
| * | Parameter | Data Type | Description | Default |
|---|---|---|---|---|
| VAR_INPUT | ||||
| B | Execute | BOOL | Upon the rising edge, all other function block inputs are read and the function is initiated. To modify an input, change the value and re-trigger the execute input. | FALSE |
| V | Append | BOOL | To select whether an existing the file on the server should be deleted and rewritten or the new data should be appended to the existing data. | FALSE |
| V | Destination | Yt_String64 | The full file name and destination on the FTP server, e.g. 'metrics/example.csv'. | STRING#'' |
| V | FTPData | Yt_CO_FTP_Data | The input structure that configures the FTP transfer such as FTP server address, port, etc. | All zeros in structure |
| V | File | Yt_String128 | The full file name on the controller, see path example in Memory area available for user files in ic92xx | STRING#'' |
| VAR_OUTPUT | ||||
| B | Done | BOOL | Set high when the commanded action has completed successfully. If another block takes control before the action is completed, the Done output will not be set. This output is reset when Execute goes low. | |
| B | Busy | BOOL | Set high upon the rising edge of the Execute input, and reset when Done, CommandAborted, or Error is true. In the case of a function block with an Enable input, a Busy output indicates the function is operating, but not ready to provide Valid information. (No Error) | |
| B | Error | BOOL | Set high if an error has occurred during the execution of the function block. This output is cleared when 'Execute' or 'Enable' goes low. | |
| B | ErrorID | UINT | If Error is true, this output provides the Error ID. This output is reset when 'Execute' or 'Enable' goes low. | |
| V | ErrorString | Yt_String256 | If 'Error' is true and it is an FTP response code related error then this output contains the response string from the FTP server. | |
Notes
- This block utilizes FTP. As a result, all FTP traffic sent and received (e.g. username, password, file data) is sent unencrypted in plain text and is visible to anyone with access to the network. This should not be a problem if the data being sent is not of a sensitive matter and the FTP server account is CHROOT'd properly (talk to your IT professional about using FTP).
- The FTP server should either have an internal/external domain name or use a static IP address because if the address changes, it will prevent the function from transferring files. See "Setup" for more details.
- The FTP user account must have "Write" privileges to successfully write files to the server. Optionally, the account may also have "Append" privileges. If files already exists and the FTP account only has "Write" privileges, then the file will be overwritten. If the file exists and the user account has "Append" privileges, then the file contents transferred will be appended to the existing file.
Error Description
Basic Functionality Example - Transferring a File
Setting up the FTP Server
In order to use this function block, a FTP server must exist. In this example a local FileZilla FTP Server will be used. Start by connecting to the server on the PC.

Begin by configuring the FTP server settings as shown below:
Create a user 'admin' with the password 'password'. Give the user Read + Write permissions. Create a folder on the desktop of the PC called 'FTP' and copy the path. Add the 'FTP' folder path as a mount point shown below, the corresponding virtual path should be set to '/'. This is the folder that will be used for the FTP server. The destination folder is empty to begin with and the FTP server log has been cleared prior to connection so that the results will be obvious.
Save the changes and start the FileZilla server.
iCube Engineer
This examples demonstrates how to configure the function using the data structure, create a file to send, and execute the Y_CO_FTP_SendFile block.
Here is the code in the "Initialize" ST program which configures the file data and the FTP structure. The FTP server is hosted on a local computer and does not have a domain name. Therefore, FTPIP was used and FTPPort was left blank as the local FTP server is configured to use the default port of 21. The LocalIP is set to the controllers IP and the username/password combination are set.
This program creates a file via the FILE_OPEN, STRING_TO_BUF, FILE_WRITE and FILE_CLOSE functions. The contents of the file in "sample_file_data" is converted from a YC_STRING128 to YC_BYTE128 via the "SAMPLE_TO_BUF" block.
Once the file is created and closed using the FILE_CLOSE function block, the file can be sent to the FTP server using Y_CO_FTP_SendFile.
The results of this block can be seen in the destination file explorer and the FTP server log:
The contents of the file match the "sample_file_data" string and the file can be seen in the explorer. In the FTP server log all of the commands sent can be viewed and it can be seen that the file was transferred properly and successfully.