Hey Barry, Your code works fine (at least with the NASA ftps). Thanks!
I knew it - everything is possible in R :) T. Hengl http://spatial-analyst.net > -----Original Message----- > From: b.rowling...@googlemail.com [mailto:b.rowling...@googlemail.com] On > Behalf Of Barry > Rowlingson > Sent: Tuesday, July 14, 2009 4:53 PM > To: Tomislav Hengl > Cc: alexandre villers; r-sig-geo@stat.math.ethz.ch > Subject: Re: [R-sig-Geo] getting subfolders in a directory on FTP (MODIS) > > On Tue, Jul 14, 2009 at 2:12 PM, Tomislav > Hengl<he...@spatial-analyst.net> wrote: > > > 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?), > > Apparently the FTP spec doesn't specify how to return a list of > directories, which, I read, "is a source of headaches to FTP client > developers". > > If you do: > > resp = getURL("ftp://n4ftl01u.ecs.nasa.gov/SAN/MOST/MOD10CM.005/") > items = strsplit(resp,"\n")[[1]] > > you get the folders (and files) but the folder names are in the form > of a unix directory listing. So you then want the last word of any > lines that start with 'd'. Lets get the lines first: > > folderLines = items[substr(items,1,1)=='d'] > > that gets you all the lines. There's probably a neater way of getting > the last word than this: > > lastBit <- function(x){x[length(x)]} > > dirs = unlist(lapply(strsplit(folderLines," "),lastBit)) > > Note this only works on the FTP server specified, other FTP servers > are at liberty to send back any dir format they want (I think I was > surprised the first time I connected to a DOS-based FTP server and saw > a DOS DIR listing!). > > Barry _______________________________________________ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo