file_transfer 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/file_transfer/sftp.rb +20 -3
- data/lib/file_transfer/version.rb +1 -1
- metadata +1 -1
data/lib/file_transfer/sftp.rb
CHANGED
@@ -5,15 +5,28 @@ module FileTransfer
|
|
5
5
|
def initialize(options = {})
|
6
6
|
options[:port] ||= 22
|
7
7
|
super(options)
|
8
|
-
connect
|
9
8
|
end
|
10
9
|
|
11
10
|
def download(from_path, to_path)
|
12
|
-
|
11
|
+
connect if closed?
|
12
|
+
timeout(300) do
|
13
|
+
@sftp.download! from_path, to_path
|
14
|
+
end
|
13
15
|
end
|
14
16
|
|
15
17
|
def upload(from_path, to_path)
|
16
|
-
|
18
|
+
connect if closed?
|
19
|
+
timeout(300) do
|
20
|
+
@sftp.upload! from_path, to_path
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def close
|
25
|
+
if @sftp && !@sftp.closed?
|
26
|
+
timeout(30) do
|
27
|
+
@sftp.close
|
28
|
+
end
|
29
|
+
end
|
17
30
|
end
|
18
31
|
|
19
32
|
private
|
@@ -22,6 +35,10 @@ module FileTransfer
|
|
22
35
|
@sftp = Net::SFTP.start(@host, @username, :password => @password, :port => @port)
|
23
36
|
end
|
24
37
|
|
38
|
+
def closed?
|
39
|
+
!@sftp || @sftp.closed?
|
40
|
+
end
|
41
|
+
|
25
42
|
def timeout(seconds, &block)
|
26
43
|
Timeout.timeout(seconds.to_i) do
|
27
44
|
block.call
|