Module SMB
In: smb.rb


The Ruby/SMB library uses the Samba libsmbclient library to communicate over the SMB protocol.

Author:Henrik Falck <hefa at>
Requires:libsmbclient, Ruby 1.6
License:Copyright (c) 2002 Henrik Falck. Released under the GNU GPL.
on_authentication    open    rename    stat   
Classes and Modules
Module SMB::Util
Class SMB::Dir
  ::Class SMB::Dir::Entry
Class SMB::File
  ::Class SMB::File::Stat
Class SMB::SmbError
Public Instance methods
open(url, mode = "r") {|resource| ...}

Open the network resource (server/workgroup/share/dir/file) at the given url.

This method can be used in place of File::open and Dir::open, which can only open files and dirs, respectively.

As with IO::open, if passed a block it yields the open resource, then ensures the resource is closed, and returns nil.


url:url to open
mode:file mode (only for opening files)

The format of an url is smb://username:password@server/share/dir/file.ext. Mode can be either in string format, as with File::open, [rwa][+], or one of IO::RDONLY, IO::WRONLY, or IO::RDWR, or:ed with any one of IO::APPEND, IO::TRUNC, and IO::CREAT.


an instance of either SMB::File or SMB::Dir (unless called with block, see above)


Errno::EINVAL:parameters are invalid,
Errno::ENOENT:resource is not found,
Errno::EACCES:permission to resource is denied.
rename(oldurl, newurl)

Renames the dir or file at the given url.


Stats file at url, returns an instance of SMB::File::Stat

on_authentication(proc = nil) {|server, share, workgroup, username, password| ...}

Registers an event handler for authentication requests.

Either in the form of a block, or a callable (Proc/Method) as an argument. In either case, it is called with the server and share names to be authenticated (authentication for the share IPC$ is requested on connection to a host); workgroup, username, and password are suggested values for these fields.

Your authentication function should return nil, or an array of three elements containing workgroup, username, and password to be used, or nil to use the suggested value.


  SMB.on_authentication do |server, share, workgroup, username, password|
    print "Enter password for smb://#{server}/#{share}: "
    [nil, ENV["USER"], readline.chomp]

Of course, in a real application you should probably use some more authentic method of authentication... See the included smbclient.rb for a simple approach.