From: Daniel Berger Date: 2006-10-11T11:54:32+09:00 Subject: [PATCH] ftp.rb - mget, mput, VERSION, rdoc Hi all, The diff below adds the mget and mput methods, a VERSION constant and some additional rdoc for ACCT, MDTM, and mtime. With this patch you can do stuff like this: FTP.open(host){ |ftp| ftp.login(user, pass) ftp.mput(Dir["*.rb"]) } I've been a few situations recently where this would be handy. :) Regards, Dan --- ftp.orig Mon Aug 28 23:11:32 2006 +++ ftp.rb Tue Oct 10 20:49:45 2006 @@ -77,6 +77,9 @@ CRLF = "\r\n" DEFAULT_BLOCKSIZE = 4096 # :startdoc: + + # The version of Net::FTP. + VERSION = '1.0.0' # When +true+, transfers are performed in binary mode. Default: +true+. attr_accessor :binary @@ -536,6 +539,21 @@ getbinaryfile(remotefile, localfile, blocksize, &block) end end + + # + # Retrieves +remote_files+ in whatever mode the session is set (text + # or binary). Note that, unlike #get, the local file names are always + # the same as the remote file names. + # + def mget(remote_files, blocksize = DEFAULT_BLOCKSIZE, &block) + remote_files.each{ |file| + if @binary + getbinaryfile(file, file, blocksize, &block) + else + gettextfile(file, file, blocksize, &block) + end + } + end # # Transfers +localfile+ to the server in binary mode, storing the result in @@ -590,7 +608,24 @@ end # - # Sends the ACCT command. TODO: more info. + # Transfers an array of +local_files+ to the server in whatever mode the + # sessions is set (text or binary). Note that, unlike #put, the remote + # file names are always identical to the local file names. + # + def mput(local_files, blocksize = DEFAULT_BLOCKSIZE, &block) + local_files.each{ |file| + if @binary + putbinaryfile(file, file, blocksize, &block) + else + puttextfile(file, file, blocksize, &block) + end + } + end + + # + # Sends the ACCT command, i.e. retrieves account information for +account+. + # Note that not all ftp servers support this command. If it's not + # supported, an FTPError is raised. # def acct(account) cmd = "ACCT " + account @@ -695,6 +730,9 @@ # Returns the last modification time of the (remote) file. If +local+ is # +true+, it is returned as a local time, otherwise it's a UTC time. # + # Note that this method sends the MDTM command to the remote ftp server, + # which may not be supported. See #mdtm for more details. + # def mtime(filename, local = false) str = mdtm(filename) ary = str.scan(MDTM_REGEXP)[0].collect {|i| i.to_i} @@ -761,7 +799,8 @@ end # - # Issues the MDTM command. TODO: more info. + # Issues the MDTM command, i.e. last modification time. Not supported + # by all ftp servers. If it's not supported, an FTPError is raised. # def mdtm(filename) resp = sendcmd("MDTM " + filename) @@ -920,4 +959,3 @@ # Documentation comments: # - sourced from pickaxe and nutshell, with improvements (hopefully) # - three methods should be private (search WRITEME) -# - two methods need more information (search TODO)