Skip to content

Commit

Permalink
Bugfix: Added FTP download to bst_websave for Matlab 2021b
Browse files Browse the repository at this point in the history
  • Loading branch information
ftadel committed Mar 1, 2022
1 parent 6858360 commit 0482142
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion toolbox/core/bst_plugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@
PlugDesc(end+1) = GetStruct('fieldtrip');
PlugDesc(end).Version = 'latest';
PlugDesc(end).AutoUpdate = 0;
PlugDesc(end).URLzip = 'ftp://ftp.fieldtriptoolbox.org/pub/fieldtrip/fieldtrip-lite-20210212.zip';
PlugDesc(end).URLzip = 'ftp://ftp.fieldtriptoolbox.org/pub/fieldtrip/fieldtrip-lite-20220228.zip';
PlugDesc(end).URLinfo = 'http://www.fieldtriptoolbox.org';
PlugDesc(end).TestFile = 'ft_defaults.m';
PlugDesc(end).ReadmeFile = 'README';
Expand Down
33 changes: 31 additions & 2 deletions toolbox/misc/bst_websave.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,37 @@
% For more information type "brainstorm license" at command prompt.
% =============================================================================@
%
% Authors: Francois Tadel, 2020
% Authors: Francois Tadel, 2022

errMsg = '';

% FTP download with Matlab >= 2021b
if (bst_get('MatlabVersion') >= 911) && ~isempty(strfind(url, 'ftp://'))
try
% Split URL in host/path
urlSplit = str_split(url, '/');
urlHost = urlSplit{2};
if (length(urlSplit) >= 3)
urlPath = sprintf('%s/', urlSplit{3:end-1});
else
urlPath = [];
end
urlFile = urlSplit{end};
% Get destination path
[destPath, destFile, destExt] = bst_fileparts(filename);
destFile = [destFile, destExt];
% Create an FTP object and downloads the file
ftpobj = ftp(urlHost);
cd(ftpobj, urlPath);
mget(ftpobj, urlFile, destPath);
close(ftpobj);
% Rename downloaded file
movefile(bst_fullfile(destPath, urlFile), bst_fullfile(destPath, destFile), 'f');
return;
catch
disp('BST> ERROR: FTP download failed.');
end
end

% Reading function: urlread replaced with webread in Matlab 2014b
if (bst_get('MatlabVersion') <= 803)
Expand All @@ -30,7 +60,6 @@
url_read_alt = @(f,u)urlwrite(u,f);
end
% Read online version.txt
errMsg = '';
try
url_read_fcn(filename, url);
catch
Expand Down

0 comments on commit 0482142

Please sign in to comment.