From: Todd Benson Date: 2007-07-18T09:59:47+09:00 Subject: Re: Net::FTP On 7/17/07, Ari Brown wrote: > Thanks! But is there a different command I can use to get just the > names? I happen to know that where I'm working, what I first collect > from my ftp.dir('*') will be all directories. How can I use that to > my advantage? > > aRi Well there's #nlst method (using openbsd site as an example): require 'net/ftp' names = nil Net::FTP.open('ftp.openbsd.org','anonymous','blah') do |ftp| ftp.chdir('/pub/OpenBSD/4.1') names = ftp.nlst('*') end p names That will give you the names of directories _and_ files _and_ links in the 4.1 directory. If you want just the directories in a directory, you can do this: require 'net/ftp' dirs = [] Net::FTP.open('ftp.openbsd.org', 'anonymous', 'blah') do |ftp| ftp.chdir('/pub/OpenBSD/4.1') dirs = ftp.ls('*').select { |item| item[0,1]=~/^[l|d]/ } end dirs.map! { |item| item.split.last } p dirs That will give you just the directory and link names in the 4.1 directory (but not if they have spaces in the name). Does that make sense at all? Todd