Class: HrrRbSftp::Server

Inherits:
Object
  • Object
show all
Includes:
Loggable
Defined in:
lib/hrr_rb_sftp/server.rb

Overview

This class implements SFTP server.

Examples:

# instantiate a server
server = HrrRbSftp::Server.new(logger: logger)

# then start the server with IO arguments
server.start(io_in, io_out, io_err)

Instance Attribute Summary

Attributes included from Loggable

#logger

Instance Method Summary collapse

Methods included from Loggable

#log_debug, #log_error, #log_fatal, #log_info, #log_warn

Constructor Details

#initialize(logger: nil) ⇒ Server

Returns a new instance of Server.

Parameters:

  • logger (Logger) (defaults to: nil)

    logger.



19
20
21
# File 'lib/hrr_rb_sftp/server.rb', line 19

def initialize logger: nil
  self.logger = logger
end

Instance Method Details

#start(io_in, io_out, io_err = nil) ⇒ Object

Starts SFTP server.

Examples:

# start a server with IO arguments
server.start(io_in, io_out, io_err)

Parameters:

  • io_in (IO)

    An IO for input.

  • io_out (IO)

    An IO for output.

  • io_err (IO) (defaults to: nil)

    An IO for debug output.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/hrr_rb_sftp/server.rb', line 34

def start io_in, io_out, io_err=nil
  log_info { "start server" }

  @io_in  = io_in
  @io_out = io_out
  @io_err = io_err

  @receiver = Receiver.new(@io_in)
  @sender   = Sender.new(@io_out)

  @version = negotiate_version

  @protocol = Protocol.new(@version, logger: logger)

  begin
    respond_to_requests
  rescue => e
    log_error { [e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join }
    raise
  ensure
    close_handles
  end

  log_info { "server finished" }
end