sambal 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +15 -0
- data/lib/sambal/version.rb +1 -1
- data/lib/sambal.rb +22 -9
- data/spec/sambal/client_spec.rb +8 -0
- metadata +2 -2
data/README.md
CHANGED
@@ -18,6 +18,21 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
$ gem install sambal
|
20
20
|
|
21
|
+
## Requirements
|
22
|
+
|
23
|
+
A working installation of samba, specifically the "smbclient" command line utility. See http://www.samba.org for more information.
|
24
|
+
On a mac this can be installed through homebrew https://github.com/mxcl/homebrew, like this:
|
25
|
+
|
26
|
+
brew install samba
|
27
|
+
|
28
|
+
On the Mac it can probably also be installed both through Fink and MacPorts.
|
29
|
+
|
30
|
+
On Linux (Ubuntu) it's as easy as:
|
31
|
+
|
32
|
+
apt-get install smbclient
|
33
|
+
|
34
|
+
It should be available in a similar way on all major Linux distributions.
|
35
|
+
|
21
36
|
## Usage
|
22
37
|
|
23
38
|
client = Sambal::Client.new(domain: 'WORKGROUP', host: '127.0.0.1', share: '', user: 'guest', password: '--no-pass', port: 445)
|
data/lib/sambal/version.rb
CHANGED
data/lib/sambal.rb
CHANGED
@@ -48,8 +48,11 @@ module Sambal
|
|
48
48
|
@o, @i, @pid = PTY.spawn("smbclient //#{options[:host]}/#{options[:share]} #{options[:password]} -W #{options[:domain]} -U #{options[:user]} -p #{options[:port]}")
|
49
49
|
#@o.set_encoding('UTF-8:UTF-8') ## don't know didn't work, we only have this problem when the files are named using non-english characters
|
50
50
|
#@i.set_encoding('UTF-8:UTF-8')
|
51
|
-
res = @o.expect(/^smb:.*\\>/, 10)[0]
|
51
|
+
res = @o.expect(/^smb:.*\\>/, 10)[0] rescue nil
|
52
52
|
@connected = case res
|
53
|
+
when nil
|
54
|
+
$stderr.puts "Failed to connect"
|
55
|
+
false
|
53
56
|
when /^put/
|
54
57
|
res['putting'].nil? ? false : true
|
55
58
|
else
|
@@ -66,8 +69,8 @@ module Sambal
|
|
66
69
|
close if @pid
|
67
70
|
exit(1)
|
68
71
|
end
|
69
|
-
rescue
|
70
|
-
raise RuntimeError.exception("Unknown Process Failed!! (#{$!.to_s})")
|
72
|
+
rescue Exception => e
|
73
|
+
raise RuntimeError.exception("Unknown Process Failed!! (#{$!.to_s}): #{e.message.inspect}\n"+e.backtrace.join("\n"))
|
71
74
|
end
|
72
75
|
end
|
73
76
|
|
@@ -89,8 +92,8 @@ module Sambal
|
|
89
92
|
end
|
90
93
|
end
|
91
94
|
|
92
|
-
def ls(
|
93
|
-
parse_files(
|
95
|
+
def ls(qualifier = '*')
|
96
|
+
parse_files(ask_wrapped('ls', qualifier))
|
94
97
|
end
|
95
98
|
|
96
99
|
def cd(dir)
|
@@ -104,7 +107,7 @@ module Sambal
|
|
104
107
|
def get(file, output)
|
105
108
|
begin
|
106
109
|
file_context(file) do |file|
|
107
|
-
response =
|
110
|
+
response = ask_wrapped 'get', [file, output]
|
108
111
|
if response =~ /^getting\sfile.*$/
|
109
112
|
Response.new(response, true)
|
110
113
|
else
|
@@ -117,7 +120,7 @@ module Sambal
|
|
117
120
|
end
|
118
121
|
|
119
122
|
def put(file, destination)
|
120
|
-
response =
|
123
|
+
response = ask_wrapped 'put', [file, destination]
|
121
124
|
if response =~ /^putting\sfile.*$/
|
122
125
|
Response.new(response, true)
|
123
126
|
else
|
@@ -132,7 +135,7 @@ module Sambal
|
|
132
135
|
File.open(t.path, 'w') do |f|
|
133
136
|
f << content
|
134
137
|
end
|
135
|
-
response =
|
138
|
+
response = ask_wrapped 'put', [t.path, destination]
|
136
139
|
if response =~ /^putting\sfile.*$/
|
137
140
|
Response.new(response, true)
|
138
141
|
else
|
@@ -147,7 +150,7 @@ module Sambal
|
|
147
150
|
def del(file)
|
148
151
|
begin
|
149
152
|
file_context(file) do |file|
|
150
|
-
response =
|
153
|
+
response = ask_wrapped 'del', file
|
151
154
|
next_line = response.split("\n")[1]
|
152
155
|
if next_line =~ /^smb:.*\\>/
|
153
156
|
Response.new(response, true)
|
@@ -204,6 +207,16 @@ module Sambal
|
|
204
207
|
end
|
205
208
|
end
|
206
209
|
|
210
|
+
def ask_wrapped(cmd,filenames)
|
211
|
+
ask wrap_filenames(cmd,filenames)
|
212
|
+
end
|
213
|
+
|
214
|
+
def wrap_filenames(cmd,filenames)
|
215
|
+
filenames = [filenames] unless filenames.kind_of?(Array)
|
216
|
+
filenames.map!{ |filename| '"' + filename + '"' }
|
217
|
+
[cmd,filenames].flatten.join(' ')
|
218
|
+
end
|
219
|
+
|
207
220
|
def parse_files(str)
|
208
221
|
files = {}
|
209
222
|
str.each_line do |line|
|
data/spec/sambal/client_spec.rb
CHANGED
@@ -161,5 +161,13 @@ describe Sambal::Client do
|
|
161
161
|
result = @sambal_client.put("jhfahsf iasifasifh", "jsfijsf ijidjag")
|
162
162
|
result.should_not be_successful
|
163
163
|
end
|
164
|
+
|
165
|
+
it 'should create commands with one wrapped filename' do
|
166
|
+
@sambal_client.wrap_filenames('cmd',['file1','file2']).should eq('cmd "file1" "file2"')
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'should create commands with more than one wrapped filename' do
|
170
|
+
@sambal_client.wrap_filenames('cmd',['file1','file2']).should eq('cmd "file1" "file2"')
|
171
|
+
end
|
164
172
|
|
165
173
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sambal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-09-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|