Skip to content

Instantly share code, notes, and snippets.

@katoy
Created October 3, 2013 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save katoy/6809787 to your computer and use it in GitHub Desktop.
Save katoy/6809787 to your computer and use it in GitHub Desktop.
ruby の Net::SCP でプログレスバーを出す。 See https://gist.github.com/drfeelngood/3784077
require 'rubygems'
require 'net/scp'
host = "xxxxxxx.ne.jp"
user = "youichikato"
src_path = "/tmp/1"
dest_path = "/tmp/2"
opts = {:password => "xxxxxxxx"}
Net::SCP.start(host, user, opts){|scp|
channel = scp.download(src_path, dest_path, {:preserve => true}) do |ch, name, sent, total|
# puts "#{name}: #{sent}/#{total}"
pct = sent / total.to_f
cnt = ( 72 * pct ).ceil
print "%-72s %.2f%%\r" % [ ("#" * cnt), ( pct * 100 ) ]
print "\n" if sent >= total
end
}
#
# $ ruby sample2.rb
# ######################################################################## 100.00%
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment