Skip to content

Commit

Permalink
Support older net-sftp API for Ruby 2.0
Browse files Browse the repository at this point in the history
Old Rubies such as Ruby 2.0 resolve a version of net-sftp that does not
have the `File#size` convenience method. To support these older
versions, use the lower level `File#stat`, which works for versions of
net-sftp all the way back to 2.1.2.

This fixes a `NoMethodError` when SFTP is used via sshkit on Ruby 2.0.
  • Loading branch information
mattbrictson committed Dec 31, 2023
1 parent 2ab75aa commit c8f9f18
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/sshkit/backends/netssh/sftp_transfer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def download!(remote, local, options)
end

def on_get(download, entry, offset, data)
entry.size ||= download.sftp.file.open(entry.remote, &:size)
entry.size ||= download.sftp.file.open(entry.remote) { |file| file.stat.size }
summarizer.call(nil, entry.remote, offset + data.bytesize, entry.size)
end

Expand Down

0 comments on commit c8f9f18

Please sign in to comment.