login about faq

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!

asked Apr 03 '15 at 14:10

Strahan's gravatar image

Strahan
1113

edited Apr 03 '15 at 14:12


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.

link

answered Apr 06 '15 at 21:54

chilkat's gravatar image

chilkat ♦♦
11.8k316358421

edited Apr 06 '15 at 21:55

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?

link

answered Apr 07 '15 at 19:09

Strahan's gravatar image

Strahan
1113

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×131

Asked: Apr 03 '15 at 14:10

Seen: 3,238 times

Last updated: Apr 07 '15 at 19:09

powered by OSQA