Sample code for 30+ languages & platforms
Classic ASP

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 Classic ASP Downloads

Classic ASP
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 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.

set ftp = Server.CreateObject("Chilkat.Ftp2")

ftp.Hostname = "ftp.example.com"
ftp.Username = "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.
ftp.Password = "myPassword"

success = ftp.Connect()
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( ftp.LastErrorText) & "</pre>"
    Response.End
End If

success = ftp.ChangeRemoteDir("public_html")
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( ftp.LastErrorText) & "</pre>"
    Response.End
End If

'  Perform a sync.
mode = 6
success = ftp.SyncLocalTree("qa_output/site",mode)
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( ftp.LastErrorText) & "</pre>"
    Response.End
End If

'  Get the list of files that were uploaded, downloaded, or deleted by that sync.
set synced = Server.CreateObject("Chilkat.StringTable")
ftp.GetSyncedFiles synced

n = synced.Count
Response.Write "<pre>" & Server.HTMLEncode( "Affected files: " & n) & "</pre>"

For i = 0 To n - 1
    relPath = synced.StringAt(i)
    If (synced.LastMethodSuccess = 0) Then
        Response.Write "<pre>" & Server.HTMLEncode( synced.LastErrorText) & "</pre>"
        Response.End
    End If

    Response.Write "<pre>" & Server.HTMLEncode( relPath) & "</pre>"
Next

success = ftp.Disconnect()
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( ftp.LastErrorText) & "</pre>"
    Response.End
End If


%>
</body>
</html>