React Native
React Native
Quote and SendCommand
See more FTP Examples
Demonstrate the Quote and SendCommand methods.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 = 'login';
ftp.password = 'password';
// Connect and login to the FTP server.
try {
await ftp.connectAsync();
} catch {
console.log(ftp.lastErrorText);
return;
}
// Tell the FTP object to keep an in-memory session log
// so we can see the commands sent to the server,
// and the responses received back.
ftp.keepSessionLog = true;
// Change the current remote directory via the Quote method:
try {
await ftp.quoteAsync('CWD junk');
} catch {
console.log(ftp.lastErrorText);
return;
}
// Move back up
// In this case, ChangeRemoteDir sends "CWD .." to the FTP server.
try {
await ftp.changeRemoteDirAsync('..');
} catch {
console.log(ftp.lastErrorText);
return;
}
// Do the same via the SendCommand method where the
// raw FTP server response is returned:
try {
const serverResponse = await ftp.sendCommandAsync('CWD junk');
console.log(serverResponse);
} catch {
console.log(ftp.lastErrorText);
}
await ftp.disconnectAsync();
console.log('Session Log:');
console.log(ftp.sessionLog);
}