Sample code for 30+ languages & platforms
React Native

Delete Files Matching Pattern

See more FTP Examples

The DeleteMatching method deletes all files in the current remote directory matching a wildcarded filename.

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 = 'www.chilkatsoft.com';
  ftp.username = 'MyLogin';
  ftp.password = 'MyPassword';

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

  // Change to the remote directory where the files to be deleted are located.
  // for the FTP account.
  try {
    await ftp.changeRemoteDirAsync('junk');
  } catch {
    console.log(ftp.lastErrorText);
    return;
  }

  // Delete all files with filenames matching "ftp_*.asp"
  const numDeleted = await ftp.deleteMatchingAsync('ftp_*.asp');
  if (numDeleted < 0) {
    console.log(ftp.lastErrorText);
    return;
  }

  await ftp.disconnectAsync();

  console.log(`${numDeleted} Files Deleted!`);
}