Sample code for 30+ languages & platforms
Android™

FTP over Implicit TLS (Ssl, AuthSsl, AutoFix)

See more FTP Examples

Demonstrates the SSL/TLS connection-mode properties Ssl, AuthSsl, and AutoFix. Setting Ssl true selects implicit FTPS, in which TLS begins immediately after the TCP connection on port 990.

Background: FTP has two ways to add TLS: implicit (this example) starts encrypted from the first byte on a dedicated port, 990; explicit (via AuthTls) connects in the clear on port 21 and issues AUTH TLS to upgrade. Explicit is the modern standard; implicit persists mainly for legacy servers. AuthSsl is an obsolete AUTH SSL variant to avoid. AutoFix, on by default, infers the mode from the port — disable it when you set these properties explicitly so it does not override your choice.

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

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

    //  Ssl = true selects IMPLICIT FTPS: TLS begins immediately after the TCP connection, before
    //  the greeting.  Port 990 is conventional for implicit FTPS.  Ssl takes priority over AuthTls
    //  and AuthSsl.
    ftp.put_Ssl(true);
    ftp.put_Port(990);

    //  AuthSsl selects the legacy AUTH SSL command and is very uncommon -- use AuthTls (explicit
    //  FTPS) for modern servers instead.  Left false here.
    ftp.put_AuthSsl(false);

    //  AutoFix (default true) automatically adjusts Ssl/AuthTls/AuthSsl based solely on the Port
    //  (21 or 990).  Disable it when setting these properties explicitly, as here.
    ftp.put_AutoFix(false);

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

    Log.i(TAG, "Connected using implicit FTPS.");

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