Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions lib/net/sftp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,24 @@ module SFTP
# set the SFTP protocol version to be used)
def self.start(host, user, ssh_options={}, sftp_options={}, &block)
session = Net::SSH.start(host, user, ssh_options)
# We only use a single option here, but this leaves room for more later
# without breaking the external API.
version = sftp_options.fetch(:version, nil)
sftp = Net::SFTP::Session.new(session, version, &block).connect!
begin
# We only use a single option here, but this leaves room for more later
# without breaking the external API.
version = sftp_options.fetch(:version, nil)
sftp = Net::SFTP::Session.new(session, version, &block).connect!

if block_given?
sftp.loop
session.close
return nil
end
if block_given?
sftp.loop
return nil
end

sftp
sftp
rescue Object
failed = true
raise
ensure
session.close if block_given? && !failed
end
rescue Object => anything
begin
session.shutdown!
Expand Down