Using the following ftp_download
method works, but if I change
ftp.getbinaryfile(file,localdir,1024) #=> Saves the file to localdir
to
ftp.getbinaryfile(file) #=> returns nil
I get nil
returned. According to
http://www.ruby-doc.org/stdlib-2.0/libdoc/net/ftp/rdoc/Net/FTP.html#method-i-getbinaryfile
inilf I set localfile
to nil
as above, the data should be retrieved and returned by the method. What am I doing wrong?
def ftp_download(domain,remotedir,filename_regex,user=nil,pwd=nil)
ftp = Net::FTP::new(domain)
if user && pwd
ftp.login(user, pwd)
end
ftp.chdir(remotedir)
fileList = ftp.nlst(filename_regex)
fileList.each do |file|
localdir=File.join(remotedir,file)
localdir=localdir[1..-1] if localdir[0]="/"
FileUtils.mkdir_p(File.dirname(localdir))
ftp.getbinaryfile(file,localdir,1024)
end
ftp.close
end