How can I automatically download from a url?
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
The following code is for automatically download the most recent hdf file from MODIS satellite ftp. They have recently changed from ftp to http. I can not modify the code.
%Download the last hdf from MIDIS for specified PATH & Tile----------------------
function FILE = MODIS_downloader(PATH,TILE,DATE)
FTP = ftp('e4ftl01.cr.usgs.gov');
YEAR = year(DATE);
MONTH = month(DATE);
for y = YEAR:-1:2000
for m = MONTH:-1:1
if (y==YEAR && m == MONTH)
LAST_DAY = day(DATE);
else
LAST_DAY = eomday(y,m);
end
for d = LAST_DAY:-1:1
FOLDER = [PATH, num2str(y), '.', pad(num2str(m), 2), '.', pad(num2str(d), 2)];
FLIST = dir(FTP, FOLDER) ;%in this ftp(FTP), go to this folder & grab the list of files
if ~isempty(FLIST)
cd(FTP, FOLDER);
for i = 1:length(FLIST) %No of files & folders within the current folder of ftp
FNAME = FLIST(i).name;% returns the name of the file in that dir
if ~(isempty(strfind(FNAME, TILE)) || isempty(strfind(FNAME, 'hdf')))
if strfind(FNAME, 'hdf') == (length(FNAME) - 2) %ensures that hdf is a file's extension and not just a part of the file name
FILE = mget(FTP, FNAME);
close(FTP);
return
end
end
end
end
end
end
end
end
0 Kommentare
Antworten (2)
Image Analyst
am 16 Jul. 2013
If you can't modify that code then I think we're done. You have to modify it to change the behavior. If you could modify it, I'd maybe suggest looking at urlread() instead of ftp() and see if that gets you anywhere. Why can't you modify it? Will someone complain, or will it break something else if you modify it?
0 Kommentare
Jim Hokanson
am 16 Jul. 2013
Use urlwrite to retrieve the file. Unfortunately http does not support directory enumeration like FTP does so you'll need to know where the file is located.
2 Kommentare
Javier
am 16 Jul. 2013
Hello Jim, I usually use URLWRITE for download a specific file via ftp, but if I wanna download a entire folder via FTP, I can do it?
REGARDS
Siehe auch
Kategorien
Mehr zu Downloads finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!