Created
October 3, 2013 13:25
-
-
Save katoy/6809787 to your computer and use it in GitHub Desktop.
ruby の Net::SCP でプログレスバーを出す。
See https://gist.github.com/drfeelngood/3784077
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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