Dart
Dart
FTPS with Mutual TLS Authentication (TLS Client Certificate)
See more FTP Examples
Demonstrates how to do mutual TLS authentication (using a client certificate from a .pfx/.p12).Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
final ftp = CkFtp2();
ftp.hostname = 'ftp.example.com';
ftp.port = 21;
// If using implicit TLS, you probably want port 990..
ftp.port = 990;
// Set this to false for implicit TLS, otherwise set to true for explicit TLS (where port is typically 21).
ftp.authTls = false;
// Set this to true for implicit TLS, otherwise set to false.
ftp.ssl = true;
final cert = CkCert();
try {
cert.loadPfxFile('qa_data/pfx/example.pfx', 'pfx_password');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// Use this certificate for our TLS mutually authenticated connection:
try {
ftp.setSslClientCert(cert);
} on ChilkatException {
print(cert.lastErrorText);
return;
}
// Establish the TLS connection with the FTP server.
try {
ftp.connectOnly();
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// If a login is required, then login with the FTP account login/password.
ftp.username = 'myLogin';
ftp.password = 'myPassword';
try {
ftp.loginAfterConnectOnly();
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// Do whatever you're doing to do ...
// upload files, download files, etc...
// .....
// .....
ftp.disconnect();
}