ztk 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ztk/ssh.rb +30 -15
- data/lib/ztk/version.rb +1 -1
- metadata +4 -4
data/lib/ztk/ssh.rb
CHANGED
@@ -109,6 +109,27 @@ module ZTK
|
|
109
109
|
}.merge(config))
|
110
110
|
end
|
111
111
|
|
112
|
+
# Starts an SSH session. Can also be used to get the Net::SSH object.
|
113
|
+
#
|
114
|
+
# Primarily used internally.
|
115
|
+
def ssh
|
116
|
+
@ssh ||= Net::SSH.start(@config.host_name, @config.user, ssh_options)
|
117
|
+
end
|
118
|
+
|
119
|
+
# Starts an SFTP session. Can also be used to get the Net::SSH object.
|
120
|
+
#
|
121
|
+
# Primarily used internally.
|
122
|
+
def sftp
|
123
|
+
@sftp ||= Net::SFTP.start(@config.host_name, @config.user, ssh_options)
|
124
|
+
end
|
125
|
+
|
126
|
+
# Close our sessions gracefully.
|
127
|
+
def close
|
128
|
+
log(:debug) { "close" }
|
129
|
+
ssh and ssh.close
|
130
|
+
sftp and sftp.close
|
131
|
+
end
|
132
|
+
|
112
133
|
# Launches an SSH console, replacing the current process with the console
|
113
134
|
# process.
|
114
135
|
#
|
@@ -152,13 +173,11 @@ module ZTK
|
|
152
173
|
log(:info) { "exec(#{command.inspect}, #{options.inspect})" }
|
153
174
|
log(:debug) { "config(#{@config.inspect})" }
|
154
175
|
|
155
|
-
@ssh ||= Net::SSH.start(@config.host_name, @config.user, ssh_options)
|
156
|
-
|
157
176
|
options = OpenStruct.new({ :silence => false }.merge(options))
|
158
177
|
log(:debug) { "options(#{options.inspect})" }
|
159
178
|
|
160
179
|
output = ""
|
161
|
-
channel =
|
180
|
+
channel = ssh.open_channel do |chan|
|
162
181
|
log(:debug) { "channel opened" }
|
163
182
|
chan.exec(command) do |ch, success|
|
164
183
|
raise SSHError, "Could not execute '#{command}'." unless success
|
@@ -199,15 +218,13 @@ module ZTK
|
|
199
218
|
# remote = File.expand_path(File.join("/tmp", "id_rsa.pub"))
|
200
219
|
# ssh.upload(local, remote)
|
201
220
|
def upload(local, remote)
|
202
|
-
log(:
|
221
|
+
log(:info) { "upload(#{local.inspect}, #{remote.inspect})" }
|
203
222
|
log(:debug) { "config(#{@config.inspect})" }
|
204
223
|
|
205
|
-
|
206
|
-
|
207
|
-
@sftp.upload!(local.to_s, remote.to_s) do |event, uploader, *args|
|
224
|
+
sftp.upload!(local.to_s, remote.to_s) do |event, uploader, *args|
|
208
225
|
case event
|
209
226
|
when :open
|
210
|
-
log(:
|
227
|
+
log(:debug) { "upload(#{args[0].local} -> #{args[0].remote})" }
|
211
228
|
when :close
|
212
229
|
log(:debug) { "close(#{args[0].remote})" }
|
213
230
|
when :mkdir
|
@@ -215,7 +232,7 @@ module ZTK
|
|
215
232
|
when :put
|
216
233
|
log(:debug) { "put(#{args[0].remote}, size #{args[2].size} bytes, offset #{args[1]})" }
|
217
234
|
when :finish
|
218
|
-
log(:
|
235
|
+
log(:debug) { "finish" }
|
219
236
|
end
|
220
237
|
end
|
221
238
|
|
@@ -238,15 +255,13 @@ module ZTK
|
|
238
255
|
# remote = File.expand_path(File.join(ENV["HOME"], ".ssh", "id_rsa.pub"))
|
239
256
|
# ssh.download(remote, local)
|
240
257
|
def download(remote, local)
|
241
|
-
log(:
|
258
|
+
log(:info) { "download(#{remote.inspect}, #{local.inspect})" }
|
242
259
|
log(:debug) { "config(#{@config.inspect})" }
|
243
260
|
|
244
|
-
|
245
|
-
|
246
|
-
@sftp.download!(remote.to_s, local.to_s) do |event, downloader, *args|
|
261
|
+
sftp.download!(remote.to_s, local.to_s) do |event, downloader, *args|
|
247
262
|
case event
|
248
263
|
when :open
|
249
|
-
log(:
|
264
|
+
log(:debug) { "download(#{args[0].remote} -> #{args[0].local})" }
|
250
265
|
when :close
|
251
266
|
log(:debug) { "close(#{args[0].local})" }
|
252
267
|
when :mkdir
|
@@ -254,7 +269,7 @@ module ZTK
|
|
254
269
|
when :get
|
255
270
|
log(:debug) { "get(#{args[0].remote}, size #{args[2].size} bytes, offset #{args[1]})" }
|
256
271
|
when :finish
|
257
|
-
log(:
|
272
|
+
log(:debug) { "finish" }
|
258
273
|
end
|
259
274
|
end
|
260
275
|
|
data/lib/ztk/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ztk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
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: 2013-01-
|
12
|
+
date: 2013-01-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: erubis
|
@@ -208,7 +208,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
208
208
|
version: '0'
|
209
209
|
segments:
|
210
210
|
- 0
|
211
|
-
hash:
|
211
|
+
hash: 3569323308884458346
|
212
212
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
213
213
|
none: false
|
214
214
|
requirements:
|
@@ -217,7 +217,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
217
217
|
version: '0'
|
218
218
|
segments:
|
219
219
|
- 0
|
220
|
-
hash:
|
220
|
+
hash: 3569323308884458346
|
221
221
|
requirements: []
|
222
222
|
rubyforge_project:
|
223
223
|
rubygems_version: 1.8.24
|