Sample code for 30+ languages & platforms
Android™

Clear the FTP Session Log

See more FTP Examples

Demonstrates the Chilkat Ftp2.ClearSessionLog method, which clears the in-memory FTP protocol log collected while KeepSessionLog is enabled. It takes no arguments.

Background: With session logging on, the SessionLog accumulates the full FTP command/reply conversation, which is invaluable for diagnosing a failed transfer. Over a long-lived session it grows unbounded, so clearing it frees memory — and, more usefully, lets you capture the log for one specific operation in isolation by clearing just before and reading just after.

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;

    //  Demonstrates the Ftp2.ClearSessionLog method, which clears the in-memory FTP protocol log.  It
    //  takes no arguments and is a void method.

    CkFtp2 ftp = new CkFtp2();

    ftp.put_Hostname("ftp.example.com");
    ftp.put_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.put_Password("myPassword");

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

    //  The SessionLog accumulates the FTP protocol conversation when KeepSessionLog is enabled, which
    //  is useful for debugging.
    ftp.put_KeepSessionLog(true);

    //  ... perform some operations ...

    //  Clear the log, for example before starting a new logical operation whose log you want to
    //  capture in isolation.
    ftp.ClearSessionLog();
    Log.i(TAG, "Session log cleared.");

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