rename
Rename a file or directory on an FTP server.
Attention: Available only with Twin Activate commercial edition.
Syntax
[R, msg] = rename(ftpObj, oldname, newname)
Inputs
- ftpObj
- FTP object
- oldname
- File or directory to be renamed.
- newname
- New file or directory name.
Outputs
- R
- Returns 0 if successful; returns 1 if not successful.
- msg
- Returns an error message if the command is not succcessful.
Examples
Rename a file:
% Create the FTP object
ftpObj = ftp('ftp://127.0.0.1:60000','user', 'password');
disp('Contents of the remote root directory:')
dir(ftpObj)
% Rename 'file1.txt' to 'file1_renamed.txt'
rename(ftpObj,'file1.txt','file1_renamed.txt');
% Check that the file is renamed
disp('Contents of the remote root directory after renaming:')
dir(ftpObj)
close(ftpObj);
Contents of the remote root directory:
ans = drwxrwxrwx 1 owner group 0 Feb 20 11:05 Folder1
drwxrwxrwx 1 owner group 0 Feb 20 11:05 Folder2
-rw-rw-rw- 1 owner group 0 Feb 19 08:53 file1.txt
-rw-rw-rw- 1 owner group 0 Feb 19 08:53 file2.txt
Contents of the remote root directory after renaming:
ans = drwxrwxrwx 1 owner group 0 Feb 20 11:05 Folder1
drwxrwxrwx 1 owner group 0 Feb 20 11:05 Folder2
-rw-rw-rw- 1 owner group 0 Feb 19 08:53 file1_renamed.txt
-rw-rw-rw- 1 owner group 0 Feb 19 08:53 file2.txt
Rename a directory:
% Create the FTP object
ftpObj = ftp('ftp://127.0.0.1:60000','user', 'password');
disp('Contents of the remote root directory:')
dir(ftpObj)
% Rename 'Folder1' to 'Folder1_renamed'
rename(ftpObj,'Folder1','Folder1_renamed');
% Check that the file is renamed
disp('Contents of the remote root directory after renaming:')
dir(ftpObj)
close(ftpObj);
Contents of the remote root directory:
ans = drwxrwxrwx 1 owner group 0 Feb 20 11:05 Folder1
drwxrwxrwx 1 owner group 0 Feb 20 11:05 Folder2
-rw-rw-rw- 1 owner group 0 Feb 19 08:53 file1.txt
-rw-rw-rw- 1 owner group 0 Feb 19 08:53 file2.txt
Contents of the remote root directory after renaming:
ans = drwxrwxrwx 1 owner group 0 Feb 20 11:05 Folder1_renamed
drwxrwxrwx 1 owner group 0 Feb 20 11:05 Folder2
-rw-rw-rw- 1 owner group 0 Feb 19 08:53 file1.txt
-rw-rw-rw- 1 owner group 0 Feb 19 08:53 file2.txt