ruby - Net::ftp getbinaryfile() saving to file vs saving to variable -
using following ftp_download
method works, if change
ftp.getbinaryfile(file,localdir,1024) #=> saves file localdir
to
ftp.getbinaryfile(file) #=> returns nil
i nil
returned. according to
http://www.ruby-doc.org/stdlib-2.0/libdoc/net/ftp/rdoc/net/ftp.html#method-i-getbinaryfile
inilf set localfile
nil
above, data should retrieved , returned method. 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 |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
if @ getbinaryfile
method signature notice default value second parameter (localfile
) not nil
file.basename(remotefile)
getbinaryfile(remotefile, localfile=file.basename(remotefile), blocksize=default_blocksize)
if want localfile
nil
have pass explicitly:
ftp.getbinaryfile(file, nil)
Comments
Post a Comment