Question:
Hi. Just wondering if I am doing this wrong... I want to sync a local directory with a remote one. I want new files to be downloaded and files that no longer exist remotely to be removed from the local path. This is what I'm doing:
success = ftp.Connect();
Write("Changing to remote folder ...");
if (!ftp.ChangeRemoteDir(fldRemote.Text)) Write(ftp.LastErrorText);
Write("Synchronizing files ...");
if (!ftp.SyncLocalTree(fldLocal.Text, 2)) Write(ftp.LastErrorText);
Write("Removing outdated files ...");
if (!ftp.SyncLocalTree(fldLocal.Text, 99)) Write(ftp.LastErrorText);
ftp.Disconnect();
Write("Session complete!");
It brings down new files, but does not delete the old ones. What am I doing wrong? Thanks!
Here's the documentation for SyncLocalTree:
Downloads files from the FTP server to a local directory tree. Synchronization modes include: mode=0: Download all files mode=1: Download all files that do not exist on the local filesystem. mode=2: Download newer or non-existant files. mode=3: Download only newer files. If a file does not already exist on the local filesystem, it is not downloaded from the server. mode=5: Download only missing files or files with size differences. mode=6: Same as mode 5, but also download newer files. mode=99: Do not download files, but instead delete remote files that do not exist locally. * There is no mode #4. It is a mode used internally by the DirTreeXml method.
Mode 2 downloads newer or non-existant files. Mode 99 deletes remote items that do not exist locally. After synchronizing with mode 2, by definition all files that existed remotely but not locally will have been downloaded, and therefore there is nothing to be deleted when the call to SyncLocalTree with mode=99 is called.
Ohh, sorry, I'm an idiot. I misread that and thought 99 meant local files get removed if they do not exist. Don't suppose there is an easy way for that is there?