React Native
React Native
SFTP Download Files Matching a Pattern
See more SFTP Examples
Demonstrates how to download files in a directory matching one or more patterns (such as "*.zip" or "abc*_*0719.csv".Chilkat React Native Downloads
import { SFtp } from '@chilkat/react-native'
async function chilkatExample() {
let success = false;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const sftp = new SFtp();
success = true;
try {
await sftp.connectAsync('my-ssh-server.com', 22);
} catch {
success = false;
}
if (success) {
success = true;
try {
await sftp.authenticatePwAsync('mySshLogin', 'mySshPassword');
} catch {
success = false;
}
}
if (success) {
success = true;
try {
await sftp.initializeSftpAsync();
} catch {
success = false;
}
}
if (!success) {
console.log(sftp.lastErrorText);
return;
}
// The SyncTreeDownload method can be used non-recursively to download all files matching a set of patterns.
// This example will download all files, but only those files having filenames
// that match *.csv and *.eml
sftp.syncMustMatch = '*.eml; *.gif';
const remoteDir = 'syncDownloadTest/someDir';
const localDir = 'qa_output';
// mode=0: Download all matching files according to SyncMustMatch
const mode = 0;
// do not recursively traverse the remote directory tree.
const recursive = false;
success = true;
try {
await sftp.syncTreeDownloadAsync(remoteDir, localDir, mode, recursive);
} catch {
success = false;
}
if (!success) {
console.log(sftp.lastErrorText);
return;
}
console.log('Success.');
}