Class: URI::SFTP
Overview
:nodoc:
Constant Summary collapse
- DEFAULT_PORT =
22
- COMPONENT =
[ :scheme, :userinfo, :host, :port, :path ].freeze
Class Method Summary collapse
-
.passwords ⇒ Object
Caching of passwords, so we only need to ask once.
Instance Method Summary collapse
-
#initialize(*arg) ⇒ SFTP
constructor
A new instance of SFTP.
- #read(options = {}, &block) ⇒ Object
Methods inherited from Generic
Constructor Details
#initialize(*arg) ⇒ SFTP
Returns a new instance of SFTP.
395 396 397 |
# File 'lib/buildr/core/transports.rb', line 395 def initialize(*arg) super end |
Class Method Details
.passwords ⇒ Object
Caching of passwords, so we only need to ask once.
390 391 392 |
# File 'lib/buildr/core/transports.rb', line 390 def passwords @passwords ||= {} end |
Instance Method Details
#read(options = {}, &block) ⇒ Object
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 |
# File 'lib/buildr/core/transports.rb', line 399 def read( = {}, &block) # SSH options are based on the username/password from the URI. = { :port=>port, :password=>password }.merge([:ssh_options] || {}) [:password] ||= SFTP.passwords[host] begin trace "Connecting to #{host}" if block result = nil else result = '' block = lambda { |chunk| result << chunk } end Net::SFTP.start(host, user, ) do |sftp| SFTP.passwords[host] = [:password] trace 'connected' [:progress] && [:size], path.split('/').last, [:size] || 0 do |progress| trace "Downloading from #{path}" sftp.file.open(path, 'r') do |file| while chunk = file.read(RW_CHUNK_SIZE) block.call chunk progress << chunk break if chunk.size < RW_CHUNK_SIZE end end end end return result rescue Net::SSH::AuthenticationFailed=>ex # Only if running with console, prompt for password. if ![:password] && $stdout.isatty password = Buildr::Console.ask_password("Password for #{host}:") { |q| q.echo = '*' } [:password] = password retry end raise end end |