I'm looking for a way to read from a samba share. I want to use it like the Dir
class, for example open and read of directories. Is this possible in Ruby?

- 26,737
- 24
- 105
- 146

- 73
- 1
- 8
-
3Dear mibo, http://www.google.com/search?gcx=c&sourceid=chrome&ie=UTF-8&q=samba+ruby+gem , Love, Google – muffinista Oct 11 '11 at 23:41
-
yes I had found. But since it is not developed, I thought maybe there is a current gem. – mibo Oct 12 '11 at 06:18
-
Sambala work with ftools but ftools is deprecated since ruby 1.9.2. So its seems to be not working for me. – mibo Oct 12 '11 at 07:32
4 Answers
The Sambala gem should work for you if your host OS is a Posix (UNIX-like) system (not sure about Windows...):
gem install sambala
This gem will work as long as your host OS has a working smbclient executable somewhere in your $PATH. As long as you're using Mac OS X, Linux, or some other UNIX variant, you should be able to run the following command from the terminal to see if you've got smbclient somewhere in your path:
which smbclient
If you don't get a result, do a google search on how to obtain smbclient for your current host OS. If you're on Mac OS X, you can simply install MacPorts and then run the following command from the terminal to get smbclient installed:
sudo port install samba3

- 578
- 5
- 14
-
Sambala work with ftools but ftools is deprecated since ruby 1.9.2. So its seems to be not working for me. – mibo Oct 12 '11 at 07:24
-
1It's not terribly complicated to replace ftools with fileutils in most cases, so you could consider forking sambala at https://github.com/lp/sambala, and update it for 1.9.2 – muffinista Oct 12 '11 at 12:58
-
1Yea, ftools isn't required in sambala, but in the abundance gem, which is required from sambala. It was not so easy to find the include of ftools because on github code ftools will not be used. But my local gem abundance use one ftool function. But it doesn't work. i can't connect to my samba share. i think i will use ssh etc to get the network shares. Anyway, thanks a lot. – mibo Oct 12 '11 at 15:58
I think you could try to check my gem, i've started it cause i've same issues with sambala

- 11
- 1
-
this is an incomplete gem a full year later. It does not provide the basic functionality requested in question. – shadowbq Jan 09 '13 at 15:42
The Sambala gem will work for 1.8.x Ruby implementations on a Posix (UNIX-like) system
gem install sambala
For 1.9.x Ruby on Posix use GLSIGNAL's fork.
git clone https://github.com/glsignal/sambala.git
cd sambala
gem build samabala
gem install ./sambala.gem
Note: GLSignal's gem uses a github source of abundance that is patched to run on 1.9.x
As stated by lottscarson, these gems will work as long as your host OS has a working smbclient executable somewhere in your $PATH. As long as you're using Mac OS X, Linux, or some other Posix variant, you should be able to run the following command from the terminal to see if you've got smbclient somewhere in your path:
which smbclient
If you don't get a result, do a google search on how to obtain smbclient for your current host OS. (examples)
(RHEL/CENTOS/etc) yum install samba
(ubuntu/debian) sudo apt-get install samba smbfs
(osx) brew install samba
As an alternative to a wrapper for smbclient you could use a C extension ruby gem called 'net-smb'. This requires native compilation, and is not written pure ruby.
gem install net-smb
This requires a few things as well.
Ruby 1.9.3+
Samba 3.5+ (libsmbclient)
C compiler
Installation examples
sudo apt-get install libsmbclient libsmbclient-dev

- 1,232
- 1
- 16
- 29
-
GLSignals version of abundance is 1.3.6, the last version by pl (the orginal author) is 1.3.5 – shadowbq Jan 09 '13 at 16:03
-
Ruby_SMB is a native Ruby implementation of the SMB Protocol Family.
From the README:
sock = TCPSocket.new address, 445
dispatcher = RubySMB::Dispatcher::Socket.new(sock)
client = RubySMB::Client.new(dispatcher, username: 'msfadmin', password: 'msfadmin')
client.negotiate
client.authenticate
begin
tree = client.tree_connect('TEST_SHARE')
puts "Connected to #{path} successfully!"
rescue StandardError => e
puts "Failed to connect to #{path}: #{e.message}"
end
files = tree.list(directory: 'subdir1')
files.each do |file|
create_time = file.create_time.to_datetime.to_s
access_time = file.last_access.to_datetime.to_s
change_time = file.last_change.to_datetime.to_s
file_name = file.file_name.encode("UTF-8")
puts "FILE: #{file_name}\n\tSIZE(BYTES):#{file.end_of_file}\n\tSIZE_ON_DISK(BYTES):#{file.allocation_size}\n\tCREATED:#{create_time}\n\tACCESSED:#{access_time}\n\tCHANGED:#{change_time}\n\n"
end