Sample code for 30+ languages & platforms
React Native

Get a Raw Text Directory Listing (LIST)

See more FTP Examples

Demonstrates the Chilkat Ftp2.GetTextDirListing method, which sends a legacy LIST request and returns the server's raw textual listing. The only argument is appended literally as a server-side listing argument; an empty string lists the current remote directory.

Background: This returns exactly what the server's LIST command produces — usually a Unix ls -l-style block, but the format is server-defined and not standardized. That makes it handy for display or debugging, but fragile to parse; prefer GetXmlDirListing or the index-based accessors when you need structured data. Since the argument is appended literally to LIST, it can carry server-specific options as well as a wildcard.

Chilkat React Native Downloads

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

async function chilkatExample() {
  // Demonstrates the Ftp2.GetTextDirListing method, which sends a legacy LIST request and returns
  // the server's raw textual listing.  The only argument is appended literally as a server-side
  // listing argument; an empty string lists the current remote directory.

  const ftp = new Ftp2();

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

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

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

  try {
    await ftp.changeRemoteDirAsync('public_html');
  } catch {
    console.log(ftp.lastErrorText);
    return;
  }

  // Get the raw listing text.  The format is server-defined (often Unix "ls -l" style).
  let listing: string;
  try {
    listing = await ftp.getTextDirListingAsync('');
  } catch {
    console.log(ftp.lastErrorText);
    return;
  }

  console.log(listing);

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