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 scp_download(remote, local, options={})
        opened = false
        args = []
        scp.download!(remote.to_s, local.to_s, options.send(:table)) do |ch, name, sent, total|
          args = [ OpenStruct.new(:size => total, :local => name, :remote => name), sent, '' ]
          opened or (options.on_progress.nil? or options.on_progress.call(:open, args) and (opened = true))
          options.ui.logger.debug { "get(#{args[0].remote}, sent #{args[1]}, total #{args[0].size})" }
          options.on_progress.nil? or options.on_progress.call(:get, args)
        end
        options.ui.logger.debug { "finish" }
        options.on_progress.nil? or options.on_progress.call(:finish, args)
      end
def scp_download ( remote , local , options = { } ) opened = false args = [ ] scp . download! ( remote . to_s , local . to_s , options . send ( :table ) ) do | ch , name , sent , total | args = [ OpenStruct . new ( :size => total , :local => name , :remote => name ) , sent , '' ] opened or ( options . on_progress . nil? or options . on_progress . call ( :open , args ) and ( opened = true ) ) options . ui . logger . debug { "get(#{args[0].remote}, sent #{args[1]}, total #{args[0].size})" } options . on_progress . nil? or options . on_progress . call ( :get , args ) end options . ui . logger . debug { "finish" } options . on_progress . nil? or options . on_progress . call ( :finish , args ) 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 )