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

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -