Android™
Android™
Set the FTP TLS Version and Ciphers
See more FTP Examples
Demonstrates the TLS negotiation properties SslProtocol and SslAllowedCiphers, and reads back the negotiated TlsVersion and TlsCipherSuite after connecting.
Background:
SslProtocol sets the allowed (or minimum) TLS version — default lets Chilkat negotiate the best available, while a value like TLS 1.2 or higher enforces a floor for policy compliance. SslAllowedCiphers narrows the offered cipher suites, which most applications should leave at the secure defaults. The read-only TlsVersion and TlsCipherSuite report what was actually agreed, useful for logging and audits.Chilkat Android™ Downloads
// 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");
ftp.put_AuthTls(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");
// Require at least TLS 1.2. Accepted values include "default", "TLS 1.3", "TLS 1.2",
// "TLS 1.2 or higher", and so on. "default" lets Chilkat negotiate the best available.
ftp.put_SslProtocol("TLS 1.2 or higher");
// Optionally restrict the cipher suites offered. Leave empty to use Chilkat's secure defaults.
ftp.put_SslAllowedCiphers("TLS_AES_256_GCM_SHA384,TLS_CHACHA20_POLY1305_SHA256");
success = ftp.Connect();
if (success == false) {
Log.i(TAG, ftp.lastErrorText());
return;
}
// After connecting, read back what was actually negotiated.
Log.i(TAG, "Negotiated TLS version: " + ftp.tlsVersion());
Log.i(TAG, "Negotiated cipher suite: " + ftp.tlsCipherSuite());
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."
}
}