我正在使用以下代码尝试使用 Ruby 从 ftp 获取所有文件。
files = ftp.list()
files.each do |file|
ftp.gettextfile(file)
end
问题是 ftp.list 返回整行信息,而不仅仅是文件名,例如
-rw-r--r-- 1 ftp ftp 0 May 31 11:18 brett.txt
如何从这个字符串中提取文件名?
非常感谢
最佳答案
您可以使用 nlst像这样的公共(public)方法
files = ftp.nlst("*.zip")|ftp.nlst("*.txt")|ftp.nlst("*.xml")
#optionally exclude falsely matched files
exclude = /\.old|temp/
#exclude files with 'old' or 'temp' in the name
files = files.reject{ |e| exclude.match e } #remove files matching the exclude regex
files.each do |file|
#do something with each file here
end
关于ruby-on-rails - Ruby Net::FTP,从 ftp.list() 中提取文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6182160/