Sample code for 30+ languages & platforms
Android™

Resolve the FTP Password from OS Secure Storage

See more FTP Examples

Demonstrates the EnableSecrets property, which lets password properties contain a secret specification beginning with !! that Chilkat resolves from the operating system's secure storage instead of using the literal text.

Background: This is a cleaner alternative to reading a secret yourself and assigning it: with EnableSecrets on, you set the password to a reference like !!my_secret_name and Chilkat fetches the real value from the platform's secure store. The literal password never appears in your source or configuration, which is exactly the practice recommended throughout these examples.

Chilkat Android™ Downloads

Android™
// 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 {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    boolean success = false;

    CkFtp2 ftp = new CkFtp2();

    ftp.put_Hostname("ftp.example.com");
    ftp.put_Username("myFtpLogin");

    //  EnableSecrets (default false) allows password properties to contain a "secret specification"
    //  beginning with "!!" that Chilkat resolves from the operating system's secure storage instead
    //  of using the literal text.
    ftp.put_EnableSecrets(true);

    //  Provide a secret specification rather than a literal password.  Chilkat looks up the named
    //  secret in the OS secure store.
    ftp.put_Password("!!my_ftp_password_secret");

    success = ftp.Connect();
    if (success == false) {
        Log.i(TAG, ftp.lastErrorText());
        return;
        }

    Log.i(TAG, "Connected using a password from OS secure storage.");

    success = ftp.Disconnect();
    if (success == false) {
        Log.i(TAG, ftp.lastErrorText());
        return;
        }


  }

  static {
      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."
  }
}