TwinCAT FTP Client: Upload of a file to a FTP Server

This sample will illustrate uploading a file from an ADS device to a FTP Server.

To execute this sample you have to create a user with the username "TestUser" and the password "TestPwd123" on the FTP Server.
If you set a rising edge at the input variable "bExecute" with the help of the variable "startstop", the file "\Program Files\TestFile1.txt" from the ADS device will be copied to the FTP Server. On the FTP Server the name of the file will be set to "\TestFolder\File1.txt". The folder "TestFolder" will be created if it isn't available.


Notice that the user "TestUser" has rights for reading and writing.

Variable declaration

PROGRAM MAIN
VAR
    FB_FTPFileUpload1   : FB_FTP_FileUploadEx;
    startstop           : BOOL;
    busy                : BOOL;
    err                 : BOOL;
    errid               : UDINT;
    progress            : UDINT;
END_VAR

PLC Program

FB_FTPFileUpload1(
    sNetID:= ,
    sHost:= '172.16.235.100',
    nPort:= DEFAULT_FTP_PORT,
    sUsername:= 'TestUser',
    sPassword:= 'TestPwd123',
    sSrcFile:= '\Program Files\TestFile1.txt',
    sDesFile:= '\TestFolder\File1.txt',
    bExecute:= startstop,
    tTimeout:= T#15s,
    bBusy=> busy,
    bError=> err,
    nErrId=> errid,
    nProgress=> progress);  

The "TcFTPClient.lib", "TcSystem.lib", "TcBase.lib" and "STANDARD.lib" libraries are to be linked.