React Native Requires Chilkat v11.0.0+
React Native
Verify FTP SSL Server Certificate
See more FTP Examples
This example demonstrates how to verify the FTP server's certificate and authenticity. The intent is to verify the authenticity of the server before passing a login/password to it.Chilkat React Native Downloads
import { Cert, Ftp2 } from '@chilkat/react-native'
async function chilkatExample() {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const ftp = new Ftp2();
ftp.hostname = 'ftp.myftpserver.com';
ftp.username = 'myUsername';
ftp.password = 'myPassword';
// Establish an AUTH SSL secure channel after connection
// on the standard FTP port 21.
ftp.authSsl = true;
// The Ssl property is for establishing an implicit SSL connection
// on port 990. Do not set it.
ftp.ssl = false;
// Indicate that the FTP server must have a verifiable SSL certificate.
// Do not accept self-signed certs or certificates that are
// expired, revoked, or cannot be verified to a root authority:
ftp.requireSslCertVerify = true;
// You may also set a requirement. In this example,
// the certificate's Common Name (CN) must match the
// required string exactly:
ftp.setSslCertRequirement('subjectcn', 'Chilkat Software, Inc.');
// Connect and login to the FTP server.
try {
await ftp.connectAsync();
} catch {
console.log(ftp.lastErrorText);
return;
}
// After logging on, you may examine the FTP server's cert:
const cert = new Cert();
try {
ftp.getServerCert(cert);
// Display the distinguished name of the SSL cert.
console.log(cert.subjectDN);
} catch {
console.log('No server certificate!');
}
console.log('Secure FTP Channel Established!');
// Do whatever you're doing to do ...
// upload files, download files, etc...
await ftp.disconnectAsync();
}