Overview FTP Upload



With this function block files can be uploaded to an FTP, SFTP or SCP server. The upload is performed for FTP by the program ftp-upload, for SFTP and SCP by the OpenSSH client (sftp or scp, each with sshpass) and is therefore only available on the Linux controller.


Inputs

TR
Trigger
On a rising edge the upload is started. If an upload of this function block is already running, the edge is ignored. An upload is aborted after 300 seconds at the latest.

Outputs

ER
Error
Return value of the upload program. 0 = upload successful, not equal to 0 = error. 124 means that the upload was aborted after 300 seconds. Negative values are internal errors: -1 = no file to upload, -2 = required program not found (for SFTP sftp or sshpass), -3 = error creating the SFTP batch file, -4 = a specified file was not found.

Parameters

Protocol
FTP: Upload via the FTP protocol (unencrypted).
SFTP: Upload via SFTP (SSH, encrypted).
SCP: Upload via SCP (SSH, encrypted). The files are copied to the home directory of the user on the server.
For SFTP and SCP the login is done with user name and password, the host key is not checked.
File name
File name; separated by a semicolon several file names can be specified.
Path
Automatic: The files are searched for in the working directory of the project, so for example CSV files do not need a path specification. The characters / \ : * ? " < > | are not allowed in a file name.
Manual: The full path of the file is specified in the parameter File name. This is only necessary for special cases. The file name is used unchanged here.
Host
Host name of the FTP, SFTP or SCP server
Port
Only for SFTP and SCP. Port of the SSH server, 0 = default port 22. For FTP this parameter is not evaluated, FTP always uses port 21.
User name
User name
Password Password. Special characters such as brackets, spaces or curly braces can be entered directly. Note when updating older projects: Previously such passwords had to be enclosed in single quotation marks. This is no longer necessary. The quotation marks have to be removed from existing projects, otherwise they are transferred as part of the password and the login to the FTP server fails. The same applies to Host, User name and File name.
Rename file Optional. With this option the file can be renamed. For example to append a date. Example: log_%d_%m_%Y.csv is renamed to log_10_11_2023.csv. If nothing is specified in this parameter, the original file name is used.
If several files are specified in the parameter File name, a separate pattern for each file can be specified here, separated by a semicolon. Example: File name log.csv;error.csv, Rename file log_%Y%m%d.csv;error_%Y%m%d.csv. For files without their own pattern the original name is used. For renaming, a copy of the file is created which is deleted again after the upload.
Rename file offset Time offset in seconds for renaming the file. For example -3600 means minus 1 hour. If the file is for example sent at 0:00h and you want to use the date of the previous day, an offset can be specified with this parameter in order to use the date of the previous day.




The following placeholders are available for renaming:

%a Abbreviated weekday name Sun
%A Full weekday name Sunday
%b Abbreviated month name Mar
%B Full month name March
%c Time+date Sun Aug 19 02:56:02 2012
%d Day of the month (01-31) 19
%H Hour in 24-hour format (00-23) 14
%I Hour in 12h format (01-12) 05
%j Day of the year (001-366) 231
%m Month as a decimal number (01-12) 08
%M Minute (00-59) 55
%p Designation AM (0-12) or PM (12-0) PM
%S Second (00-61) 02
%U Week number with the first Sunday as the first day of the first week (00-53) 33
%w Weekday as a decimal number with Sunday as 0 (0-6) 4
%W Week number with the first Monday as the first day of the first week (00-53) 34
%x Date 08/19/12
%X Time 02:50:06
%y Year, last two digits (00-99) 01
%Y Year 2012
%Z Name or abbreviation of the time zone CDT
%% Percent sign %



See also common parameters of all function blocks.