Sample code for 30+ languages & platforms
React Native

Get Filenames in a Remote Directory

Gets the names of files in a remote FTP directory.

Chilkat React Native Downloads

React Native
import { 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';
  ftp.username = 'myLogin';
  ftp.password = 'myPassword';
  // Use explicit TLS
  ftp.authTls = true;
  ftp.port = 21;

  // Connect and login to the FTP server.
  try {
    await ftp.connectAsync();
  } catch {
    console.log(ftp.lastErrorText);
    return;
  }

  // Iterate over .txt files.
  ftp.listPattern = '*.txt';
  const n = await ftp.getDirCountAsync();
  console.log(`n = ${n}`);

  let i = 0;
  while (i < n) {

    console.log(`${i}: ${await ftp.getFilenameAsync(i)}`);

    i++;
  }
}