lib/ztk/ssh/upload.rb
# Uploads a local file to a remote host.
#
# @example Upload 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(ENV['HOME'], ".ssh", "id_rsa.pub"))
#   remote = File.expand_path(File.join(ZTK::Locator.root, "tmp", "id_rsa.pub"))
#   ssh.upload(local, remote)
#
# @param [String] local The local file/path you wish to upload from.
# @param [String] remote The remote file/path you with to upload to.
# @param [Hash] options An optional hash of options.
# @option options [Boolean] :recursive (false) Whether or not to
#   recursively download files and directories.
# @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.
Uploads a local file to a remote host.
Uploads a local file to a remote host .
def sftp_upload(local, remote, options={})
        sftp.upload!(local.to_s, remote.to_s) do |event, uploader, *args|
          case event
          when :open
            options.ui.logger.debug { "upload(#{args[0].local} -> #{args[0].remote})" }
            options.on_progress.nil? or options.on_progress.call(:open, args)
          when :close
            options.ui.logger.debug { "close(#{args[0].remote})" }
            options.on_progress.nil? or options.on_progress.call(:close, args)
          when :mkdir
            options.ui.logger.debug { "mkdir(#{args[0]})" }
            options.on_progress.nil? or options.on_progress.call(:mkdir, args)
          when :put
            options.ui.logger.debug { "put(#{args[0].remote}, size #{args[2].size} bytes, offset #{args[1]})" }
            options.on_progress.nil? or options.on_progress.call(:put, args)
          when :finish
            options.ui.logger.debug { "finish" }
            options.on_progress.nil? or options.on_progress.call(:finish, args)
          end
        end
      end
def sftp_upload ( local , remote , options = { } ) sftp . upload! ( local . to_s , remote . to_s ) do | event , uploader , * args | case event when :open options . ui . logger . debug { "upload(#{args[0].local} -> #{args[0].remote})" } options . on_progress . nil? or options . on_progress . call ( :open , args ) when :close options . ui . logger . debug { "close(#{args[0].remote})" } options . on_progress . nil? or options . on_progress . call ( :close , args ) when :mkdir options . ui . logger . debug { "mkdir(#{args[0]})" } options . on_progress . nil? or options . on_progress . call ( :mkdir , args ) when :put options . ui . logger . debug { "put(#{args[0].remote}, size #{args[2].size} bytes, offset #{args[1]})" } options . on_progress . nil? or options . on_progress . call ( :put , args ) when :finish options . ui . logger . debug { "finish" } options . on_progress . nil? or options . on_progress . call ( :finish , args ) end end end
Uploads a local file to a remote host.
Uploads a local file to a remote host .
True if successful.
True if successful .
Boolean
local
<not_specific>
remote
<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
Upload 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(ENV['HOME'], ".ssh", "id_rsa.pub")) remote = File.expand_path(File.join(ZTK::Locator.root, "tmp", "id_rsa.pub")) ssh.upload(local, remote)
Upload 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 ( ENV [ ' HOME ' ] " . ssh " " id_rsa . pub " )) remote = File . expand_path ( File . join ( ZTK :: Locator . root " tmp " " id_rsa . pub " )) ssh . upload ( local remote )