[R-sig-Geo] getting subfolders in a directory on FTP (MODIS)

Tomislav Hengl hengl at spatial-analyst.net
Tue Jul 14 15:12:07 CEST 2009


> -----Original Message-----
> From: r-sig-geo-bounces at stat.math.ethz.ch [mailto:r-sig-geo-bounces at stat.math.ethz.ch] On Behalf
> Of alexandre villers
> Sent: Tuesday, July 14, 2009 10:47 AM
> To: r-sig-geo at stat.math.ethz.ch
> Subject: [R-sig-Geo] getting subfolders in a directory on FTP (MODIS)
> 
> Good morning,
> 
> I know this is not exactly a question for R SIG GEO, but as it may interest beginners like me who
> work with MODIS data... (and I'm hoping I'm not the only beginner on the list !)
> I adapted the script of Tomislav Hengl (again thank you for your wiki page! http://spatial-
> analyst.net/wiki/index.php?title=Main_Page) to download snow cover MODIS data form NSIDC
> (http://nsidc.org/) from their ftp site (the data I'm interested in lie in
> ftp://n4ftl01u.ecs.nasa.gov/SAN/MOST/MOD10CM.005/ <-- monthly snow cover). MODIS data are stored
> in subfolders named by their dates and I already had the same troubles with other MODIS data. How
> do I get the list of subfolders name directly from R and thus the dates of satellite pictures ?

If the directories were on you machine, you would list them using:

> library(R.utils)
> ld <- listDirectory(R.home(), recursive=TRUE, fullNames=TRUE)

To tell you honestly, I could not figure out how to fetch names of sub-folders from an ftp (maybe it
is simply not possible?), but to list all files is not a problem:

> tmp <- strsplit(getURL("ftp://n4ftl01u.ecs.nasa.gov/SAN/MOST/MOD10CM.005/2000.04.01/",
.opts=curlOptions(ftplistonly=TRUE)), "\r\n")[[1]]
> tmp[1:2]
[1] "MOD10CM.A2000092.005.2007180145722.hdf"    
[2] "MOD10CM.A2000092.005.2007180145722.hdf.xml"

Maybe you should take a better look at the "RCurl" library (maybe wget is the solution?
http://users.ugent.be/~bpuype/wget/).

It's not really such a big problem because you only need to get the names of the subfolders (dates)
once, which are in principle unique for most of the MODIS products. You can also write them by hand
e.g.:

dates <- data.frame(dirname=c("2001.08.13", "2002.08.13", "2003.08.13", "2004.08.12", "2005.08.13",
"2006.08.13", "2007.08.13", "2008.08.12"))

> For the moment, what I've been doing is going on the ftp via my browser, copy and paste the whole
> page in a .txt file and manage that with excel to get the dates... But I don't really like doing
> it that way.
> So if anyone could guide me to a R function that would do that (or to the different functions if
> it's not straigthforward)...
> 
> Best regards
> 
> 
> Alex
> Alexandre Villers
> PhD. Student
> Team Biodiversity
> CEBC CNRS
> 79360 Beauvoir sur Niort
> 
> 
> __________ Information from ESET Mail Security, version of virus signature database 4240
> (20090713) __________
> 
> The message was checked by ESET Mail Security.
> http://www.eset.com
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

T. Hengl
http://spatial-analyst.net/wiki/index.php?title=Download_and_resampling_of_MODIS_images



More information about the R-sig-Geo mailing list