필터 지우기
필터 지우기

How can I automatically download from a url?

조회 수: 4 (최근 30일)
Ali
Ali 2013년 7월 15일
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

답변 (2개)

Image Analyst
Image Analyst 2013년 7월 16일
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?

Jim Hokanson
Jim Hokanson 2013년 7월 16일
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
Javier
Javier 2013년 7월 16일
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
Ali
Ali 2013년 7월 16일
Thank you very much. I will try.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Downloads에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by