The base class for all SFTP operations. Subclasses must implement a perform method, which accepts the arguments expected by the corresponding method of the driver. Subclasses may also override the default implementations of do_status, do_data, do_name, do_handle, and do_attrs, as necessary.
Status | = | Struct.new( :code, :message, :language ) |
A structure for reporting status information. | ||
OK | = | Status.new( FX_OK, "Success", "" ) |
A constant for representing the commonly-used FX_OK status. |
Create a new operation with the given logger instance, which will operate atop the given session, using the given driver to format and send the requests to the server.
[ show source ]
# File lib/net/sftp/operations/abstract.rb, line 38 38: def initialize( log, session, driver ) 39: @log = log 40: @session = session 41: @driver = driver 42: end
A callback for SFTP attrs packets. By default, invokes the registered callback, passing an OK status and the attributes object.
[ show source ]
# File lib/net/sftp/operations/abstract.rb, line 102 102: def do_attrs( attributes ) 103: @callback[ OK, attributes ] 104: end
A callback for SFTP data packets. By default, invokes the registered callback, passing an OK status and the data.
[ show source ]
# File lib/net/sftp/operations/abstract.rb, line 90 90: def do_data( data ) 91: @callback[ OK, data ] 92: end
A callback for SFTP handle packets. By default, invokes the registered callback, passing an OK status and the handle.
[ show source ]
# File lib/net/sftp/operations/abstract.rb, line 84 84: def do_handle( handle ) 85: @callback[ OK, handle ] 86: end
A callback for SFTP name packets. By default, invokes the registered callback, passing an OK status and the list of items.
[ show source ]
# File lib/net/sftp/operations/abstract.rb, line 96 96: def do_name( items ) 97: @callback[ OK, items ] 98: end
A callback for SFTP status packets. By default, raises an exception unless the status is FX_OK, in which case the registered callback is invoked.
[ show source ]
# File lib/net/sftp/operations/abstract.rb, line 77 77: def do_status( code, message, language ) 78: raise StatusException.new( code, message, language ) unless code == FX_OK 79: @callback[ Status.new( code, message, language ) ] 80: end
Execute the operation. If a callback is given, the operation will be performed asynchronously with the callback being invoked when the operation completes. If a callback is not given, the operation will be performed synchronously, with the expected value being returned.
[ show source ]
# File lib/net/sftp/operations/abstract.rb, line 48 48: def execute( *args, &callback ) 49: @log.debug "executing" if @log.debug? 50: 51: unless block_given? 52: status = result = nil 53: callback = Proc.new do |status, *pargs| 54: status = status 55: result = case 56: when pargs.empty? then @session.status 57: when pargs.length == 1 then pargs.first 58: else pargs 59: end 60: end 61: end 62: 63: @callback = callback 64: @id = perform *args 65: @log.debug "received request id #{@id}" 66: @session.register( @id, self ) 67: 68: unless block_given? 69: @session.loop { status.nil? } 70: @session.status = status 71: return result 72: end 73: end