React Native
React Native
FTP Upload / Download to a BinData Object
Demonstrates how to FTP upload the contents of a BinData object, and FTP downloads to the a BinData object.Chilkat React Native Downloads
import { BinData, Ftp2 } from '@chilkat/react-native'
async function chilkatExample() {
// This example assumes Chilkat Ftp2 to have been previously unlocked.
// See Unlock Ftp2 for sample code.
const ftp = new Ftp2();
ftp.hostname = 'www.my-ftp-server.com';
ftp.username = 'mFtpLogin';
ftp.password = 'myFtpPassword';
// Connect to the FTP server.
try {
await ftp.connectOnlyAsync();
} catch {
console.log(ftp.lastErrorText);
return;
}
// Authenticate with the FTP server.
try {
await ftp.loginAfterConnectOnlyAsync();
} catch {
console.log(ftp.lastErrorText);
return;
}
const bdA = new BinData();
bdA.loadFile('qa_data/jpg/penguins.jpg');
// Upload the contents of bdA to the FTP server.
const remoteFilename = 'penguins.jpg';
try {
await ftp.putFileBdAsync(bdA, remoteFilename);
} catch {
console.log(ftp.lastErrorText);
return;
}
// Download...
const bdB = new BinData();
try {
await ftp.getFileBdAsync(remoteFilename, bdB);
} catch {
console.log(ftp.lastErrorText);
return;
}
// Verify that bdA and bdB have the exact same contents.
console.log(`size of bdA: ${bdA.numBytes}`);
if (bdA.contentsEqual(bdB)) {
console.log('Contents are equal. Success.');
} else {
console.log('Contents are NOT equal. Failed.');
}
await ftp.disconnectAsync();
}