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.
@@ -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
- @sftp.download! from_path, to_path
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
- @sftp.upload! from_path, to_path
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
@@ -1,3 +1,3 @@
1
1
  module FileTransfer # :nodoc:
2
- VERSION = "0.0.1" # :nodoc:
2
+ VERSION = "0.0.2" # :nodoc:
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: file_transfer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: