Sample code for 30+ languages & platforms
React Native

FTPS with Client Cert from Windows Certificate Store

See more FTP Examples

Demonstrates how to do mutual TLS authentication using a client certificate installed in the Windows certificate store.

Chilkat React Native Downloads

React Native
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.example.com';

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

  const cert = new Cert();
  try {
    cert.loadByCommonName('The common name of your certificate');
  } catch {
    console.log(cert.lastErrorText);
    return;
  }

  // Use this certificate for our TLS mutually authenticated connection:
  try {
    ftp.setSslClientCert(cert);
  } catch {
    console.log(cert.lastErrorText);
    return;
  }

  // Establish the TLS connection with the FTP server.
  try {
    await ftp.connectOnlyAsync();
  } catch {
    console.log(ftp.lastErrorText);
    return;
  }

  // If a login is required, then login with the FTP account login/password.
  ftp.username = 'myLogin';
  ftp.password = 'myPassword';
  try {
    await ftp.loginAfterConnectOnlyAsync();
  } catch {
    console.log(ftp.lastErrorText);
    return;
  }

  // Do whatever you're doing to do ...
  // upload files, download files, etc...

  // .....
  // .....

  await ftp.disconnectAsync();
}