Class: FileTransfer::FileTransferHandler
- Inherits:
-
Object
- Object
- FileTransfer::FileTransferHandler
- Defined in:
- lib/file_transfer/file_transfer_handler.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #close ⇒ Object
-
#download(paths) ⇒ Array
Downloads data from server.
- #exist?(path) ⇒ Boolean
-
#initialize(type, options) ⇒ FileTransferHandler
constructor
A new instance of FileTransferHandler.
- #list(path) ⇒ Object
- #remove(path) ⇒ Object
- #rename(from_path, to_path) ⇒ Object
- #test_connection ⇒ Object
-
#upload(paths) ⇒ Array
Uploads data to server.
Constructor Details
#initialize(type, options) ⇒ FileTransferHandler
Returns a new instance of FileTransferHandler.
6 7 8 9 10 |
# File 'lib/file_transfer/file_transfer_handler.rb', line 6 def initialize(type, ) @type = type @options = @client = get_client type, end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
4 5 6 |
# File 'lib/file_transfer/file_transfer_handler.rb', line 4 def client @client end |
Instance Method Details
#close ⇒ Object
81 82 83 |
# File 'lib/file_transfer/file_transfer_handler.rb', line 81 def close client.close end |
#download(paths) ⇒ Array
Downloads data from server
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/file_transfer/file_transfer_handler.rb', line 49 def download(paths) paths = normalize_paths paths all_file_paths = [] # Loop over Path Specs paths.each do |path| # Make sure it's an Array of from-Paths path[:from] = [path[:from]] unless path[:from].kind_of?(Array) && path[:from][0].kind_of?(Array) # Loop over Path From Specs path[:from].each do |path_pattern| _download path_pattern, path[:to] all_file_paths.push path_pattern end end all_file_paths end |
#exist?(path) ⇒ Boolean
77 78 79 |
# File 'lib/file_transfer/file_transfer_handler.rb', line 77 def exist?(path) client.exist? path end |
#list(path) ⇒ Object
65 66 67 |
# File 'lib/file_transfer/file_transfer_handler.rb', line 65 def list(path) client.list path end |
#remove(path) ⇒ Object
69 70 71 |
# File 'lib/file_transfer/file_transfer_handler.rb', line 69 def remove(path) client.remove path end |
#rename(from_path, to_path) ⇒ Object
73 74 75 |
# File 'lib/file_transfer/file_transfer_handler.rb', line 73 def rename(from_path, to_path) client.rename from_path, to_path end |
#test_connection ⇒ Object
12 13 14 |
# File 'lib/file_transfer/file_transfer_handler.rb', line 12 def test_connection client.test_connection end |
#upload(paths) ⇒ Array
Uploads data to server
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/file_transfer/file_transfer_handler.rb', line 19 def upload(paths) paths = normalize_paths paths all_file_paths = [] # Loop over Path Specs paths.each do |path| # Make sure it's an Array of from-Paths path[:from] = [path[:from]] unless path[:from].kind_of?(Array) && path[:from][0].kind_of?(Array) # Loop over Path From Specs path[:from].each do |path_pattern| path_pattern = [path_pattern] unless path_pattern.kind_of?(Array) file_paths = [] if File.exists?(path_pattern[0]) && File.directory?(path_pattern[0]) path_pattern[1] = '*.*' if path_pattern.length < 2 Dir.chdir(path_pattern[0]) file_paths = Dir.glob(path_pattern[1]) elsif File.exists?(path_pattern[0]) file_paths = [path_pattern[0]] end file_paths.each do |file_path| _upload file_path, path[:to] all_file_paths.push file_path end end end all_file_paths end |