Skip to content

Commit 3cb9766

Browse files
committed
Implement the upload! and download! methods for the local backend
1 parent 0dedaa6 commit 3cb9766

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

lib/sshkit/backends/local.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'open3'
2+
require 'fileutils'
23
module SSHKit
34

45
module Backend
@@ -31,6 +32,26 @@ def capture(*args)
3132
_execute(*[*args, options]).full_stdout
3233
end
3334

35+
def upload!(local, remote, options = {})
36+
if local.is_a?(String)
37+
FileUtils.cp(local, remote)
38+
else
39+
File.open(remote, "wb") do |f|
40+
IO.copy_stream(local, f)
41+
end
42+
end
43+
end
44+
45+
def download!(remote, local=nil, options = {})
46+
if local.nil?
47+
FileUtils.cp(remote, File.basename(remote))
48+
else
49+
File.open(remote, "rb") do |f|
50+
IO.copy_stream(f, local)
51+
end
52+
end
53+
end
54+
3455
private
3556

3657
def _execute(*args)

0 commit comments

Comments
 (0)