Sample code for 30+ languages & platforms
Android™

FTP Automatic Post-Connect Commands

See more FTP Examples

Demonstrates the AutoFeat, AutoSyst, AutoOptsUtf8, and AutoXcrc properties, which control commands Chilkat issues automatically around connecting and transferring.

Background: Chilkat normally probes and adapts to a server on its own: AutoFeat discovers capabilities with FEAT, AutoSyst learns the OS type to parse legacy listings, and AutoOptsUtf8 enables UTF-8 filenames when the server advertises it. These are on by default and rarely worth changing. AutoXcrc is the exception worth enabling deliberately — it verifies each upload with the server's XCRC checksum, catching corruption automatically where supported.

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");

    //  These auto-* properties control commands Chilkat sends automatically after connecting.  They
    //  are on/off by default as noted, and are rarely changed.

    //  AutoFeat (default true): automatically send FEAT to discover server capabilities.
    ftp.put_AutoFeat(true);

    //  AutoSyst (default true): automatically send SYST after login to learn the server OS type.
    ftp.put_AutoSyst(true);

    //  AutoOptsUtf8 (default true): send OPTS UTF8 ON when the FEAT response advertises UTF8.
    ftp.put_AutoOptsUtf8(true);

    //  AutoXcrc (default false): request an XCRC checksum after each upload and treat a mismatch as
    //  a failure, giving automatic post-upload verification where the server supports XCRC.
    ftp.put_AutoXcrc(true);

    //  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;
        }

    Log.i(TAG, "Connected with the configured automatic features.");

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