Sample code for 30+ languages & platforms
Dart

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 Dart Downloads

Dart
import 'package:chilkat/chilkat.dart';

void main() {
  // This example requires the Chilkat API to have been previously unlocked.
  // See Global Unlock Sample for sample code.

  final ftp = CkFtp2();

  ftp.hostname = 'ftp.example.com';
  ftp.username = 'login';
  ftp.password = 'password';

  // Connect and login to the FTP server.
  try {
    ftp.connect();
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  // Set the current remote directory to where the file
  // is located:
  try {
    ftp.changeRemoteDir('/testing');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  // Rename the remote file (or directory)
  final existingFilename = 'hello.txt';
  final newFilename = 'goodbye.txt';
  try {
    ftp.renameRemoteFile(existingFilename, newFilename);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  ftp.disconnect();
}