Giter Club home page Giter Club logo

sambal's Introduction

Test status

Sambal

Sambal is a ruby samba client

Quite a bit of code was borrowed from https://github.com/reivilo/rsmbclient - Thanks!

Installation

Add this line to your application's Gemfile:

gem 'sambal'

And then execute:

$ bundle

Or install it yourself as:

$ gem install sambal

Requirements

A working installation of samba, specifically the "smbclient" command line utility. See http://www.samba.org for more information. On a mac this can be installed through homebrew https://github.com/mxcl/homebrew, like this:

brew install samba

On Linux (Ubuntu) it's as easy as:

apt-get install smbclient

It should be available in a similar way on all major Linux distributions.

If you happen to be running NixOS or at least the Nix package manager you could just use the flake.nix file in this repo. That should also set you up for running the tests (which require samba). Something like this:

nix develop
bundle install
bundle exec rspec

Usage

client = Sambal::Client.new(domain: 'WORKGROUP', host: '127.0.0.1', share: '', user: 'guest', password: '--no-pass', port: 445)
client.ls # returns hash of files
client.put("local_file.txt","remote_file.txt") # uploads file to server
client.exists?("remote_file.txt") # checks if file is on server
client.put_content("My content here", "remote_file") # uploads content to a file on server
client.get("remote_file.txt", "local_file.txt") # downloads file from server
client.del("remote_file.txt") # deletes files from server
client.exists?("some_directory") # checks if directory is on server
client.cd("some_directory") # changes directory on server
client.close # closes connection

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

sambal's People

Contributors

alexanderlisay avatar antstorm avatar buzztaiki avatar dependabot[bot] avatar domcleal avatar dougkeller avatar iberianpig avatar johnae avatar jsteen-mpr avatar manoktsina avatar mikepollitt avatar nakamuta918 avatar np422 avatar odebe avatar oz-tal avatar ringe avatar skeemer avatar tab10id avatar vtamara avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

sambal's Issues

File without any flags is not listed by ls

Henlo!

A curious case, a file without any flags set won't be listed by the ls method of the sambal client.

Some of the information below have been redacted to protect the innocent.

smbclient -I prd-db-w01 -U XXXX YYYY .....
cd /some/strange/path
smb: \some\strange\path\ > ls
  .                                   D        0  Wed Nov  3 10:22:12 2021
  ..                                  D        0  Wed Nov  3 10:21:57 2021
  ID_84389_7601003001921_211111012316880071_20211116164659941.pdf          166155  Wed Nov 17 16:40:46 2021

When using sambal in irb.

irb(main):001:0> require 'sambal'
irb(main):002:0> smb = Sambal::Client.new(domain: 'ZZZ', host: 'prd-db-w01', share: 'FS_PRD', user: 'XXX', password: 'YYY')
irb(main):003:0> smb.cd '/some/strange/path'
irb(main):004:0> smb.ls
=> {"."=>{:type=>:directory, :size=>"0", :modified=>2021-11-03 10:22:12 +0100}, ".."=>{:type=>:directory, :size=>"0", :modified=>2021-11-03 10:21:57 +0100}}

And after toggling the archive flag, using file explorer.

smb: \some\strange\path\> ls
  .                                   D        0  Wed Nov  3 10:22:12 2021
  ..                                  D        0  Wed Nov  3 10:21:57 2021
  ID_84389_7601003001921_211111012316880071_20211116164659941.pdf      A   166155  Wed Nov 17 16:40:46 2021

The response from the sambal client.

irb(main):005:0> smb.ls
=> {"."=>{:type=>:directory, :size=>"0", :modified=>2021-11-03 10:22:12 +0100}, ".."=>{:type=>:directory, :size=>"0", :modified=>2021-11-03 10:21:57 +0100}, "ID_84389_7601003001921_211111012316880071_20211116164659941.pdf"=>{:type=>:file, :size=>"166155", :modified=>2021-11-17 16:40:46 +0100}}

The behaviour is likely caused by the + sign on https://github.com/johnae/sambal/blob/master/lib/sambal/client.rb#L291

If this is the expected behaviour, please feel free to slap me with a dead trout and close the issue.

Smbclient response when trying to cd to a non-existing directory

When the version of smbclient I use tries to cd to a non existing directory it will respond with NT_STATUS_OBJECT_PATH_NOT_FOUND.

The Client#cd method searches for the string NT_STATUS_OBJECT_NAME_NOT_FOUND in the response

A regex that tries to find both is used in pull request #53

`rescue in initialize': Unknown Process Failed!! (Input/output error - /dev/ttys002)

Got this error when trying to use Sambal. I believe it's related to the smbclient bug connecting via LDAP for authentication.

code

require 'sambal'

client = Sambal::Client.new(domain: 'corp', host: '192.168.3.10', share: 'Releases', user: 'release-bot', password: '<masked>', port: 445)
client.ls
client.close # closes connection

error log

Failed to connect
/Users/xbeta/.rvm/gems/ruby-1.9.3-p392/gems/sambal-0.1.2/lib/sambal.rb:73:in `rescue in initialize': Unknown Process Failed!! (Input/output error - /dev/ttys002): "Input/output error - /dev/ttys002" (RuntimeError)
/Users/xbeta/.rvm/gems/ruby-1.9.3-p392/gems/sambal-0.1.2/lib/sambal.rb:229:in `write'
/Users/xbeta/.rvm/gems/ruby-1.9.3-p392/gems/sambal-0.1.2/lib/sambal.rb:229:in `printf'
/Users/xbeta/.rvm/gems/ruby-1.9.3-p392/gems/sambal-0.1.2/lib/sambal.rb:229:in `close'
/Users/xbeta/.rvm/gems/ruby-1.9.3-p392/gems/sambal-0.1.2/lib/sambal.rb:69:in `initialize'
./publish_to_smb.rb:6:in `new'
./publish_to_smb.rb:6:in `<main>'
    from /Users/xbeta/.rvm/gems/ruby-1.9.3-p392/gems/sambal-0.1.2/lib/sambal.rb:46:in `initialize'
    from ./publish_to_smb.rb:6:in `new'
    from ./publish_to_smb.rb:6:in `<main>'

Failing to use sambal command on irb console / rails console

=> #<Sambal::Client:0x00005581c1efc368 @timeout=10, @output=#<File:/dev/pts/2>, @input=#<File:/dev/pts/2>, @pid=7649, @connected=true>
irb(main):005:0> client.ls
Failed to do ls "*"
Traceback (most recent call last):
        7: from /usr/local/bin/irb:23:in `<main>'
        6: from /usr/local/bin/irb:23:in `load'
        5: from /usr/local/lib/ruby/gems/2.6.0/gems/irb-1.0.0/exe/irb:11:in `<top (required)>'
        4: from (irb):5
        3: from /usr/local/bundle/gems/sambal-0.2.2/lib/sambal/client.rb:98:in `ls'
        2: from /usr/local/bundle/gems/sambal-0.2.2/lib/sambal/client.rb:266:in `ask_wrapped'
        1: from /usr/local/bundle/gems/sambal-0.2.2/lib/sambal/client.rb:259:in `ask'
RuntimeError (Failed to do ls "*")

These are the scenarios ive tried with sambal client on rails and its seems like im failing to use commands on rails console only

  • smbclient (ok)
  • rails console (fail)
  • telnet (ok)

my gem version is 0.2.2

new rubygem version

hi -- can you please release the current version of this gem on rubygems?
thanks!

Problems with Exception (Failed to do cd "path");

Hey guys,

I'm having some trouble with this exception in production.

In development it works fine, on rails console too. But on my server raises exception

      params      = { domain:   'domain',
                      host:     'ip',
                      share:    'folder',
                      user:     'username',
                      password: 'pass' }
      path        = 'my_path'
      file = 'file'
      samba       = Sambal::Client.new(params)
      samba.cd(path)
      samba.get(file, 'local_dir/filename')
      samba.close

What is going wrong?

Remote file md5sum

Hi, Thanks for the gem. I have a quick question. Is there any way we can get the md5sum of a remote file?

If you are unable to add this feature, I am happy to do it but need some help to get started though.

Need a better test infrastructure

So far the tests, some of them, have booted up smbd. It's necessary to do that for the integration tests. This infrastructure is failing now because of changes in smbd.
Needs to be fixed. Perhaps there's a better way to do this.

Doesn't connect if options[:host] != default_options[:host]

If the host is different from the default_options -> 127.0.0.1... it fails to connect because the option flags is constructed as:

option_flags = "-W \"#{options[:domain]}\" -U \"#{options[:user]}\" -I #{options[:ip_address]} -p #{options[:port]}"

and since options[:ip_address] is blank, it will fail. I tested manually and removing the -I entirely makes it work again. Adding a conditional t o include -I options[:ip_address] only when options[:ip_address].present? should fix the problem.

I have problem running on OpenBSD/adJ 5.8

When running

require 'sambal' 

client = Sambal::Client.new(domain: 'domain', host: '192.168.1.1', share: 'share', user: 'user', password: 'pass', port: 445)

It produces

/usr/local/lib/ruby/gems/2.3/gems/sambal-0.1.7/lib/sambal/client.rb:39:in `rescue in initialize': Unknown Process Failed!! (can't get Master/Slave device): "can't get Master/Slave device" (RuntimeError)
/usr/local/lib/ruby/gems/2.3/gems/sambal-0.1.7/lib/sambal/client.rb:16:in `spawn'
/usr/local/lib/ruby/gems/2.3/gems/sambal-0.1.7/lib/sambal/client.rb:16:in `initialize'
herram/pruebasambal.rb:7:in `new'
herram/pruebasambal.rb:7:in `<main>'
        from /usr/local/lib/ruby/gems/2.3/gems/sambal-0.1.7/lib/sambal/client.rb:13:in `initialize'
        from herram/pruebasambal.rb:3:in `new'
        from herram/pruebasambal.rb:3:in `<main>'

I guess it has to do more with the ruby interpreter on my platform.

$ ruby -v
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-openbsd]

Doesn't work on Windows; cannot load such file pty

C:\www\dashstats\logs>gem install sambal
Fetching: sambal-0.1.7.gem (100%)
Successfully installed sambal-0.1.7
1 gem installed

C:\www\dashstats\logs>irb
irb(main):001:0> require 'sambal'
LoadError: cannot load such file -- pty
        from C:/Ruby/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        from C:/Ruby/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        from C:/Ruby/lib/ruby/gems/2.2.0/gems/sambal-0.1.7/lib/sambal/client.rb:4:in `<top (required)>'
        from C:/Ruby/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        from C:/Ruby/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        from C:/Ruby/lib/ruby/gems/2.2.0/gems/sambal-0.1.7/lib/sambal.rb:5:in `<top (required)>'
        from C:/Ruby/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:in `require'
        from C:/Ruby/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:in `rescue in require'
        from C:/Ruby/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:39:in `require'
        from (irb):1
        from C:/Ruby/bin/irb:11:in `<main>'
irb(main):002:0> RUBY_VERSION
=> "2.2.6"

Doesn't handles files with consecutive whitespace characters

Your regex for parsing the result of the ls command assumes files cannot have consecutive whitespaces characters, but they can, in which case your ls returns garbage entries. I would do a patch, but I'm actually no longer using your library for the project I'm working on. I just thought you'd like to know of the problem.

Something like this may be a more robust...

/\s*(.+?)\s+([A-Z])\s+([0-9]+)\s+(.+)/

Cheers,
Tom

close doesn't finish smbclient process

In a rails application where I use sambal, after transferring a file and closing connection I see smbclient processes running.

I'm using OpenBSD/adJ 5.6 on amd64 with ruby 2.2.2, samba-3.6.15p14 and latest sambal.

I could replicate the problem with the following program:

require 'sambal'

client = Sambal::Client.new(domain: 'WORKGROUP', host: '192.168.10.40', share: 'MyShare$', user: 'myuser', password: 'mypassword', port: 445)
client.get("V92/1000/503798.TIF", "y.tif")
puts client.ls
client.close

while true do
end   

Before running in a terminal I see:

$ ps ax | grep smb
28413 pa  R+      0:00.00 grep smb

While it runs but after client.close I see:

$ ps ax | grep smb                    
17938 p9  Ss+     0:00.07 sh -c smbclient //192.168.10.40/MyShare$ mypassword -W WORKGROUP -U myuser -p 445
29222 p9  S+      0:00.01 smbclient //192.168.10.40/MyShare$ mypassword -W WORKGROUP -U myuser -p 445
 5367 pa  R+      0:00.00 grep smb

I was able to fix. God's wanting I'll send pull request.

Unknown Process Failed exit

Hello,
after initialize client I get this error:

smb = Sambal::Client.new(
    domain:    Rails.application.secrets.domain,
    host:      Rails.application.secrets.host,
    share:     Rails.application.secrets.share,
    user:      Rails.application.secrets.user, 
    password:  Rails.application.secrets.password,
    port:      Rails.application.secrets.port)
Failed to connect
RuntimeError: Unknown Process Failed!! (exit): "exit"

Any suggestion how fix it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.