mget
Download file(s) over FTP connection in the current working directory.
Attention: Available only with Twin Activate commercial edition.
Syntax
[R, msg] = mget(ftpObj, filename)
[R, msg] = mget(ftpObj, filename, localfilename)
[R, msg] = mget(ftpObj, directory)
[R, msg] = mget(ftpObj, dirname, 'recursive', recursiveFlag)
Inputs
- ftpObj
- FTP object
- filename
- File to download. Relative path to the file may also be used. The filename can contain wildcards.
- localfilename
- Name to save downloaded file as. If a localfilename is given then the filename cannot contain wildcards.
- dirname
- Directory to download files from. If a directory name is passed then all files in the directory are downloaded.
- recursiveFlag
- If 'true' then all sub-directories of the given dirname are downloaded recursively. The file/directory structure of the remote location is replicated in the local current working directory.
Outputs
- R
- Returns 1 if successful; returns 0 if not successful.
- msg
- Returns an error message if the command is not succcessful.
Examples
Get a single file:
% Create the FTP object
ftpObj = ftp('ftp://127.0.0.1:60000','user', 'password');
disp('Contents of the remote root directory:')
dir(ftpObj)
% Get the 'file1.txt'
mget(ftpObj, 'file1.txt')
% Check that 'file1.txt' has been downloaded
disp('Contents of the local current directory:')
dir()
close(ftpObj);
Contents of the remote root directory:
ans = drwxrwxrwx 1 owner group 0 Feb 19 10:00 Folder1
drwxrwxrwx 1 owner group 0 Feb 19 08:53 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 local current directory:
[.]
[..]
file1.txt
Download a file and save it locally under a different name:
% Create the FTP object
ftpObj = ftp('ftp://127.0.0.1:60000','user', 'password');
disp('Contents of the remote root directory:')
dir(ftpObj)
% Download 'file1.txt' and save it locally with the name 'downloadedFile.txt'
mget(ftpObj, 'file1.txt', 'downloadedFile.txt');
% Check that the file has been downloaded
disp('Contents of the local current directory:')
dir()
close(ftpObj);
Contents of the remote root directory:
ans = drwxrwxrwx 1 owner group 0 Feb 19 10:00 Folder1
drwxrwxrwx 1 owner group 0 Feb 19 08:53 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 local current directory:
[.]
[..]
downloadedFile.txt
Get multiple files using a wildcard:
% Create the FTP object
ftpObj = ftp('ftp://127.0.0.1:60000','user', 'password');
disp('Contents of the remote root directory:')
dir(ftpObj)
% Get all files starting with 'file'
mget(ftpObj, 'file*');
% Check that both 'file1.txt' and 'file2.txt' have been downloaded
disp('Contents of the local current directory:')
dir()
close(ftpObj);
Contents of the remote root directory:
ans = drwxrwxrwx 1 owner group 0 Feb 19 10:00 Folder1
drwxrwxrwx 1 owner group 0 Feb 19 08:53 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 local current directory:
[.]
[..]
file1.txt
file2.txt
Get all files of a directory:
% Create the FTP object
ftpObj = ftp('ftp://127.0.0.1:60000','user', 'password');
disp('Contents of ''Folder1'' in the FTP server:')
dir(ftpObj,'Folder1')
% Get all the files of the remote directory
mget(ftpObj, 'Folder1');
% Check that all files from the remote directory have been downloaded
disp('Contents of the local current directory:')
dir()
close(ftpObj);
Contents of 'Folder1' in the FTP server:
ans = -rw-rw-rw- 1 owner group 0 Feb 19 08:52 file1_1.txt
-rw-rw-rw- 1 owner group 0 Feb 19 08:52 file1_2.txt
Contents of the local current directory:
[.]
[..]
file1_1.txt
file1_2.txt
Get all files and sub-directories recursively:
% Create the FTP object
ftpObj = ftp('ftp://127.0.0.1:60000','user', 'password');
disp('Contents of ''Folder2'' in the FTP server:')
dir(ftpObj,'Folder2')
% Get all the files and directories recursivelly
mget(ftpObj, 'Folder2', 'recursive', true);
% Check that all files from the remote directory have been downloaded
disp('Contents of the local current directory:')
dir()
close(ftpObj);
Contents of 'Folder2' in the FTP server:
ans = drwxrwxrwx 1 owner group 0 Feb 20 09:36 Folder2_1
-rw-rw-rw- 1 owner group 0 Feb 19 08:53 file2_1.txt
-rw-rw-rw- 1 owner group 0 Feb 19 08:53 file2_2.txt
Contents of the local current directory:
[.]
[..]
file2_1.txt
file2_2.txt
[Folder2_1]