lib/ztk/ssh/download.rb
# Downloads a remote file to the local host.
#
# @example Download a file:
#   $logger = ZTK::Logger.new(STDOUT)
#   ssh = ZTK::SSH.new
#   ssh.config do |config|
#     config.user = ENV["USER"]
#     config.host_name = "127.0.0.1"
#   end
#   local = File.expand_path(File.join(ZTK::Locator.root, "tmp", "id_rsa.pub"))
#   remote = File.expand_path(File.join(ENV['HOME'], ".ssh", "id_rsa.pub"))
#   ssh.download(remote, local)
#
# @param [String] remote The remote file/path you with to download from.
# @param [String] local The local file/path you wish to download to.
# @param [Hash] options An optional hash of options.
# @option options [Boolean] :recursive (false) Whether or not to
#   recursively download files and directories.  By default this looks at
#   the local target and if it is a directory this is set to *true*
#   otherwise it will default to *false*.
# @option options [Boolean] :use_scp (false) If set to true, the file will
#   be transfered using SCP instead of SFTP.  The default behaviour is to
#   use SFTP.  *WARNING: Recursive downloads are handled in differing
#   manners between SCP and SFTP!*
# @return [Boolean] True if successful.
Downloads a remote file to the local host.
Downloads a remote file to the local host .
def download(remote, local, options={})
        options = {
          :recursive => ::File.directory?(local),
          :use_scp => false
        }.merge(options)
        options = OpenStruct.new(config.send(:table).merge(options))
        options.ui.logger.debug { "config=#{config.send(:table).inspect}" }
        options.ui.logger.debug { "options=#{options.send(:table).inspect}" }
        options.ui.logger.info { "download(#{remote.inspect}, #{local.inspect})" }
        ZTK::RescueRetry.try(:ui => config.ui, :tries => ZTK::SSH::RESCUE_RETRY_ATTEMPTS, :on_retry => method(:on_retry)) do
          if (options.use_scp == true)
            scp_download(remote, local, options)
          else
            sftp_download(remote, local, options)
          end
        end
        true
      end
def download ( remote , local , options = { } ) options = { :recursive => :: File . directory? ( local ) , :use_scp => false } . merge ( options ) options = OpenStruct . new ( config . send ( :table ) . merge ( options ) ) options . ui . logger . debug { "config=#{config.send(:table).inspect}" } options . ui . logger . debug { "options=#{options.send(:table).inspect}" } options . ui . logger . info { "download(#{remote.inspect}, #{local.inspect})" } ZTK :: RescueRetry . try ( :ui => config . ui , :tries => ZTK :: SSH :: RESCUE_RETRY_ATTEMPTS , :on_retry => method ( :on_retry ) ) do if ( options . use_scp == true ) scp_download ( remote , local , options ) else sftp_download ( remote , local , options ) end end true end
Downloads a remote file to the local host.
Downloads a remote file to the local host .
True if successful.
True if successful .
Boolean
remote
<not_specific>
local
<not_specific>
options
:use_scp (false) If set to true, the file will be transfered using SCP instead of SFTP. The default behaviour is to use SFTP. *WARNING: Recursive downloads are handled in differing manners between SCP and SFTP!
: use_scp ( false ) If set to true the file will be transfered using SCP instead of SFTP . The default behaviour is to use SFTP . * WARNING : Recursive downloads are handled in differing manners between SCP and SFTP!
<not_specific>
options An optional hash of options.
options An optional hash of options .
example
Download a file: $logger = ZTK::Logger.new(STDOUT) ssh = ZTK::SSH.new ssh.config do |config| config.user = ENV["USER"] config.host_name = "127.0.0.1" end local = File.expand_path(File.join(ZTK::Locator.root, "tmp", "id_rsa.pub")) remote = File.expand_path(File.join(ENV['HOME'], ".ssh", "id_rsa.pub")) ssh.download(remote, local)
Download a file : $logger = ZTK :: Logger . new ( STDOUT ) ssh = ZTK :: SSH . new ssh . config do |config| config . user = ENV [ " USER " ] config . host_name = " 127 . 0 . 0 . 1 " end local = File . expand_path ( File . join ( ZTK :: Locator . root " tmp " " id_rsa . pub " )) remote = File . expand_path ( File . join ( ENV [ ' HOME ' ] " . ssh " " id_rsa . pub " )) ssh . download ( remote local )