React Native Requires Chilkat v11.0.0+
React Native
FTP Set Remote File Date/Time Equal to Local File's Last-Modified Date/Time
See more FTP Examples
Demonstrates how to set a remote file's date/time to be equal to a local file's date/time.Important: Not all FTP servers support the ability to set a file's date/time.
Chilkat React Native Downloads
import { CkDateTime, FileAccess, 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.authtls-ftps-server.com';
ftp.username = 'FTP_LOGIN';
ftp.password = 'FTP_PASSWORD';
ftp.authTls = true;
ftp.port = 21;
// Connect to the FTP server using explicit TLS (AUTH TLS).
try {
await ftp.connectOnlyAsync();
} catch {
console.log(ftp.lastErrorText);
return;
}
// Authenticate.
try {
await ftp.loginAfterConnectOnlyAsync();
} catch {
console.log(ftp.lastErrorText);
return;
}
// We're going to get the last-mod date/time for the local file
// "qa_data/hamlet.xml", and then set the remote "hamlet.xml" to this date/time.
const fac = new FileAccess();
const dt = new CkDateTime();
const lastModTimestamp = fac.getFileTimeStr('qa_data/hamlet.xml', 0);
dt.setFromTimestamp(lastModTimestamp);
try {
await ftp.setRemoteFileDtAsync(dt, 'hamlet.xml');
} catch {
console.log(ftp.lastErrorText);
return;
}
await ftp.disconnectAsync();
console.log('Success.');
}