Class: SMB::Client
- Inherits:
-
Object
- Object
- SMB::Client
- Includes:
- ClientHelper
- Defined in:
- lib/smb/client/client.rb,
lib/smb/client/version.rb,
lib/smb/client/runtime_error.rb,
lib/smb/client/connection_error.rb
Overview
Low-level interface to smbclient executable
Defined Under Namespace
Classes: ConnectionError, RuntimeError
Constant Summary collapse
- VERSION =
'0.1.6'.freeze
Instance Attribute Summary collapse
-
#executable ⇒ Object
Returns the value of attribute executable.
-
#pid ⇒ Object
Returns the value of attribute pid.
Instance Method Summary collapse
-
#close ⇒ Object
Closes the connection to the server end terminates all running threads.
-
#exec(cmd) ⇒ Object
Execute a smbclient command.
-
#initialize(options = {}) ⇒ Client
constructor
Creates a new instance and connects to server.
Methods included from ClientHelper
#del, #exist?, #get, #ls, #mkdir, #put, #read, #rmdir, #write
Constructor Details
#initialize(options = {}) ⇒ Client
Creates a new instance and connects to server
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/smb/client/client.rb', line 19 def initialize( = {}) @executable = ENV.fetch('SMBCLIENT_EXECUTABLE') { 'smbclient' } @options = { user: [:user], share: [:share], password: [:password], version: [:version] || 2, host: [:host] || 'localhost', workgroup: [:workgroup] || 'WORKGROUP' } Thread.abort_on_exception = true connect # Pipe used to pass commands to pty @read1, @write1 = IO.pipe # Pipe used to pass responses from pty @read2, @write2 = IO.pipe # Indicates if first output should be ignored @first_message = true @connection_established = false @shutdown_in_progress = false end |
Instance Attribute Details
#executable ⇒ Object
Returns the value of attribute executable.
15 16 17 |
# File 'lib/smb/client/client.rb', line 15 def executable @executable end |
#pid ⇒ Object
Returns the value of attribute pid.
15 16 17 |
# File 'lib/smb/client/client.rb', line 15 def pid @pid end |
Instance Method Details
#close ⇒ Object
Closes the connection to the server end terminates all running threads
47 48 49 50 |
# File 'lib/smb/client/client.rb', line 47 def close @shutdown_in_progress = true Process.kill('QUIT', @pid) == 1 end |
#exec(cmd) ⇒ Object
Execute a smbclient command
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/smb/client/client.rb', line 54 def exec(cmd) # Send command @write1.puts cmd # Wait for response text = @read2.read # Close previous pipe @read2.close # Create new pipe @read2, @write2 = IO.pipe # Raise at the end to support continuing raise Client::RuntimeError, text if text.start_with? 'NT_STATUS_' text end |