Sample code for 30+ languages & platforms
React Native

Verify and Pin the FTPS Server Certificate

See more FTP Examples

Demonstrates the certificate-verification properties RequireSslCertVerify, TlsPinSet, and the read-only SslServerCertVerified.

Background: By default a TLS connection is not rejected merely because certificate-chain verification fails, so RequireSslCertVerify = true is the important hardening step — it makes an expired, unsigned, or untrusted certificate abort the connection. TlsPinSet adds public-key pinning on top: the handshake fails unless the server's SPKI fingerprint matches one you configured, defending against a mis-issued certificate that would otherwise validate. Pinning supplements verification rather than replacing it. SslServerCertVerified reports the outcome.

Chilkat React Native Downloads

React Native
import { Ftp2 } from '@chilkat/react-native'

async function chilkatExample() {
  const ftp = new Ftp2();

  ftp.hostname = 'ftp.example.com';
  ftp.username = 'myFtpLogin';

  ftp.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.password = 'myPassword';

  // Reject the connection if the server certificate cannot be verified (expired, bad signature,
  // untrusted chain, etc.).  The default is false, which does not reject on verification
  // failure -- set true for security.
  ftp.requireSslCertVerify = true;

  // Optionally pin the server's public key.  If none of the configured SPKI fingerprints matches,
  // the TLS handshake fails.  Pinning supplements normal verification; it does not replace it.
  ftp.tlsPinSet = 'sha256//YLh1dUR9y6Kja30RrAn7JKnbQG/uEtLMkBgFF2Fuihg=';

  try {
    await ftp.connectAsync();
  } catch {
    console.log(ftp.lastErrorText);
    return;
  }

  // SslServerCertVerified reports whether the certificate chain was successfully verified.
  if (ftp.sslServerCertVerified) {
    console.log('The server certificate was verified.');
  }

  try {
    await ftp.disconnectAsync();
  } catch {
    console.log(ftp.lastErrorText);
    return;
  }
}