|
|
(Chilkat for Android™ API) Synchronize Local Directory Tree
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.
Download: Chilkat for Android™ Java Libraries
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;
import android.app.Activity;
import com.chilkatsoft.*;
import android.widget.TextView;
import android.os.Bundle;
public class SimpleActivity extends Activity {
// Called when the activity is first created.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
String outStr = "";
CkFtp2 ftp = new CkFtp2();
boolean success;
// Any string unlocks the component for the 1st 30-days.
success = ftp.UnlockComponent("Anything for 30-day trial");
if (success != true) {
outStr += ftp.lastErrorText() + "\n";
tv.setText(outStr);
setContentView(tv);
return;
}
// Note: This is a valid FTP account that you may use for testing.
ftp.put_Hostname("ftp.secureftp-test.com");
ftp.put_Username("test");
ftp.put_Password("test");
ftp.put_KeepSessionLog(true);
// Connect and login to the FTP server.
success = ftp.Connect();
if (success != true) {
outStr += ftp.lastErrorText() + "\n";
tv.setText(outStr);
setContentView(tv);
return;
}
// Set the current remote directory to the root of
// the tree to be downloaded.
success = ftp.ChangeRemoteDir("/subDir1");
if (success != true) {
outStr += ftp.lastErrorText() + "\n";
tv.setText(outStr);
setContentView(tv);
return;
}
// Recursively download all non-existant and newer files.
int mode;
mode = 2;
success = ftp.SyncLocalTree("c:/temp/subDir1",mode);
if (success != true) {
outStr += ftp.lastErrorText() + "\n";
tv.setText(outStr);
setContentView(tv);
return;
}
ftp.Disconnect();
// Display the session log.
outStr += ftp.sessionLog() + "\n";
tv.setText(outStr);
setContentView(tv);
}
static {
// Important: Make sure the name passed to loadLibrary matches the shared library
// found in your project's libs/armeabi directory.
// for "libchilkat.so", pass "chilkat" to loadLibrary
// for "libchilkatemail.so", pass "chilkatemail" to loadLibrary
// etc.
//
System.loadLibrary("chilkat");
// Note: If the incorrect library name is passed to System.loadLibrary,
// then you will see the following error message at application startup:
//"The application <your-application-name> has stopped unexpectedly. Please try again."
}
}
|