React Native
React Native
Rename Remote File
See more FTP Examples
Rename a remote file or directory. The RenameRemoteFile can be called to rename either a remote file or directory.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;
}
// Set the current remote directory to where the file
// is located:
try {
await ftp.changeRemoteDirAsync('/testing');
} catch {
console.log(ftp.lastErrorText);
return;
}
// Rename the remote file (or directory)
const existingFilename = 'hello.txt';
const newFilename = 'goodbye.txt';
try {
await ftp.renameRemoteFileAsync(existingFilename, newFilename);
} catch {
console.log(ftp.lastErrorText);
return;
}
await ftp.disconnectAsync();
}