Perl
Perl
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 Perl Downloads
use strict;
use warnings;
use Chilkat2;
# This example requires the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
my $ftp = Chilkat2::Ftp2->new;
$ftp->Hostname('ftp.example.com');
$ftp->Username('login');
$ftp->Password('password');
# Connect and login to the FTP server.
my $success = $ftp->Connect();
if (!$success) {
print $ftp->LastErrorText, "\n";
exit;
}
# Set the current remote directory to where the file
# is located:
$success = $ftp->ChangeRemoteDir('/testing');
if (!$success) {
print $ftp->LastErrorText, "\n";
exit;
}
# Rename the remote file (or directory)
my $existingFilename = 'hello.txt';
my $newFilename = 'goodbye.txt';
$success = $ftp->RenameRemoteFile($existingFilename, $newFilename);
if (!$success) {
print $ftp->LastErrorText, "\n";
exit;
}
$success = $ftp->Disconnect();