Sample code for 30+ languages & platforms
PureBasic

Get the Files Affected by an FTP Sync

See more FTP Examples

Demonstrates the Chilkat Ftp2.GetSyncedFiles method, which reports the relative paths affected by the most recent synchronization. The only argument is a StringTable that receives the paths (uploaded, downloaded, or deleted).

Background: A sync call reports only overall success, but you usually want to know what actually changed — for logging, for triggering follow-up work on just the new files, or to confirm an incremental sync did the minimal transfer. An empty result is meaningful too: it means everything was already up to date. Call it immediately after the sync, before another operation replaces the recorded list.

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkFtp2.pb"
IncludeFile "CkStringTable.pb"

Procedure ChilkatExample()

    success.i = 0

    ;  Demonstrates the Ftp2.GetSyncedFiles method, which reports the relative paths affected by the
    ;  most recent synchronization operation.  The only argument is a StringTable that receives the
    ;  paths.

    ftp.i = CkFtp2::ckCreate()
    If ftp.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkFtp2::setCkHostname(ftp, "ftp.example.com")
    CkFtp2::setCkUsername(ftp, "myFtpLogin")

    ;  Normally you would not hard-code the password in source.  You should instead obtain it
    ;  from an interactive prompt, environment variable, or a secrets vault.
    CkFtp2::setCkPassword(ftp, "myPassword")

    success = CkFtp2::ckConnect(ftp)
    If success = 0
        Debug CkFtp2::ckLastErrorText(ftp)
        CkFtp2::ckDispose(ftp)
        ProcedureReturn
    EndIf

    success = CkFtp2::ckChangeRemoteDir(ftp,"public_html")
    If success = 0
        Debug CkFtp2::ckLastErrorText(ftp)
        CkFtp2::ckDispose(ftp)
        ProcedureReturn
    EndIf

    ;  Perform a sync.
    mode.i = 6
    success = CkFtp2::ckSyncLocalTree(ftp,"qa_output/site",mode)
    If success = 0
        Debug CkFtp2::ckLastErrorText(ftp)
        CkFtp2::ckDispose(ftp)
        ProcedureReturn
    EndIf

    ;  Get the list of files that were uploaded, downloaded, or deleted by that sync.
    synced.i = CkStringTable::ckCreate()
    If synced.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkFtp2::ckGetSyncedFiles(ftp,synced)

    n.i = CkStringTable::ckCount(synced)
    Debug "Affected files: " + Str(n)
    i.i
    For i = 0 To n - 1
        relPath.s = CkStringTable::ckStringAt(synced,i)
        If CkStringTable::ckLastMethodSuccess(synced) = 0
            Debug CkStringTable::ckLastErrorText(synced)
            CkFtp2::ckDispose(ftp)
            CkStringTable::ckDispose(synced)
            ProcedureReturn
        EndIf

        Debug relPath
    Next

    success = CkFtp2::ckDisconnect(ftp)
    If success = 0
        Debug CkFtp2::ckLastErrorText(ftp)
        CkFtp2::ckDispose(ftp)
        CkStringTable::ckDispose(synced)
        ProcedureReturn
    EndIf



    CkFtp2::ckDispose(ftp)
    CkStringTable::ckDispose(synced)


    ProcedureReturn
EndProcedure