Class: SSHKit::Backend::Libssh

Inherits:
Abstract
  • Object
show all
Defined in:
lib/sshkit/backends/libssh.rb

Overview

SSHKit backend class for libssh.

See Also:

Since:

  • 0.1.0

Defined Under Namespace

Classes: Configuration

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.poolSSHKit::Backend::ConnectionPool

Connection pool for libssh.

Returns:

  • (SSHKit::Backend::ConnectionPool)


98
99
100
# File 'lib/sshkit/backends/libssh.rb', line 98

def pool
  @pool
end

Class Method Details

.configConfiguration

Global configuration for Netssh.

Returns:

Since:

  • 0.1.0



102
103
104
# File 'lib/sshkit/backends/libssh.rb', line 102

def config
  @config ||= Configuration.new
end

Instance Method Details

#download!(remote, local, _options = {}) ⇒ Object

TODO:

Make options compatible with Netssh#download!.

Download a remote file to local.

Parameters:

  • remote (String)

    Path to the remote file to be downloaded.

  • local (String, #write)

    Path to the local file. If local responds to #write, local is treated as IO-like object.

See Also:

  • Abstract#download!.

Since:

  • 0.2.0



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/sshkit/backends/libssh.rb', line 73

def download!(remote, local, _options = {})
  with_session do |session|
    scp = LibSSH::Scp.new(session, :read, remote)
    scp.init do
      loop do
        case scp.pull_request
        when LibSSH::Scp::REQUEST_NEWFILE
          info "Downloading #{remote}"
          download_file(scp, local)
        when LibSSH::Scp::REQUEST_NEWDIR
          scp.deny_request('Only NEWFILE is acceptable')
        when LibSSH::Scp::REQUEST_EOF
          break
        end
      end
    end
  end
end

#upload!(local, remote, _options = {}) ⇒ Object

TODO:

Make options compatible with Netssh#upload!.

Upload a local file to the remote party.

Parameters:

  • local (String, #read)

    Path to the local file to be uploaded. If local responds to #read, local is treated as IO-like object.

  • remote (String)

    Path to the remote file.

See Also:

  • Abstract#upload!.

Since:

  • 0.2.0



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/sshkit/backends/libssh.rb', line 48

def upload!(local, remote, _options = {})
  with_session do |session|
    scp = LibSSH::Scp.new(session, :write, File.dirname(remote))
    wrap_local_reader(local) do |io, mode|
      scp.init do
        scp.push_file(File.basename(remote), io.size, mode)
        info "Uploading #{remote}"
        begin
          loop do
            scp.write(io.readpartial(BUFSIZ))
          end
        rescue EOFError # rubocop:disable Lint/HandleExceptions
        end
      end
    end
  end
end