React Native
React Native
Download Multiple Files Matching Pattern
See more FTP Examples
The MGetFiles method can be called to download all files matching a wildcarded filename pattern.Chilkat React Native Downloads
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 = 'myUsername';
ftp.password = 'myPassword';
ftp.port = 21;
ftp.authTls = true;
// 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 are located.
// This step is only necessary if the files are not in the root directory
// of the FTP account.
try {
await ftp.changeRemoteDirAsync('qa');
} catch {
console.log(ftp.lastErrorText);
return;
}
// Download all files with filenames matching "*.txt";
// The files are downloaded into c:/temp/qa_output
const numFilesDownloaded = await ftp.mGetFilesAsync('*.txt', 'c:/temp/qa_output');
if (numFilesDownloaded < 0) {
console.log(ftp.lastErrorText);
return;
}
await ftp.disconnectAsync();
console.log(`${numFilesDownloaded} Files Downloaded!`);
}