React Native
React Native
FTP Upload with Progress Event Callbacks
See more FTP Examples
FTP upload with progress event callbacks.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();
// Called with the percent completed (0..100) while an ...Async method runs.
ftp.onPercentDone = (pctDone) => {
console.log(`Percent Done: ${pctDone}`);
};
ftp.onProgressInfo = (name, value) => {
console.log(`${name}: ${value}`);
};
ftp.hostname = 'ftp.someFtpServer.com';
ftp.username = 'my_ftp_username';
ftp.password = 'my_ftp_password';
// Connect and login to the FTP server.
try {
await ftp.connectAsync();
} catch {
console.log(ftp.lastErrorText);
return;
}
// Change to the remote directory where the file will be uploaded.
try {
await ftp.changeRemoteDirAsync('junk');
} catch {
console.log(ftp.lastErrorText);
return;
}
// Upload a file.
const localPath = 'c:/temp/hamlet.xml';
const remoteFilename = 'hamlet.xml';
try {
await ftp.putFileAsync(localPath, remoteFilename);
} catch {
console.log(ftp.lastErrorText);
return;
}
await ftp.disconnectAsync();
console.log('File Uploaded!');
}