file_transfer 0.0.7 → 0.0.9
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/file_transfer_handler.rb +96 -96
 - data/lib/file_transfer/ftp.rb +82 -82
 - data/lib/file_transfer/ftps.rb +4 -4
 - data/lib/file_transfer/generic.rb +58 -57
 - data/lib/file_transfer/sftp.rb +65 -61
 - data/lib/file_transfer/version.rb +3 -3
 - data/lib/file_transfer.rb +95 -95
 - data/spec/file_transfer/file_transfer_handler_spec.rb +151 -151
 - data/spec/file_transfer/generic_spec.rb +66 -0
 - data/spec/file_transfer/sftp_spec.rb +22 -0
 - data/spec/file_transfer_spec.rb +137 -0
 - data/spec/spec_helper.rb +98 -19
 - metadata +118 -131
 - data/spec/test_files/Chrysanthemum.jpg +0 -0
 - data/spec/test_files/Desert.jpg +0 -0
 - data/spec/test_files/Hydrangeas.jpg +0 -0
 - data/spec/test_files/empty_file_from_sftp.csv +0 -1
 - data/spec/test_files/folder1/Koala.jpg +0 -0
 - data/spec/test_files/folder1/Lighthouse.jpg +0 -0
 - data/spec/test_files/folder1/text_3.txt +0 -1
 - data/spec/test_files/folder1/text_4.txt +0 -1
 - data/spec/test_files/folder2/Jellyfish.jpg +0 -0
 - data/spec/test_files/folder2/Penguins.jpg +0 -0
 - data/spec/test_files/folder2/Tulips.jpg +0 -0
 - data/spec/test_files/folder2/text_1.txt +0 -1
 - data/spec/test_files/folder2/text_6.txt +0 -1
 - data/spec/test_files/text_1.txt +0 -1
 - data/spec/test_files/text_2.txt +0 -1
 
    
        data/lib/file_transfer.rb
    CHANGED
    
    | 
         @@ -1,95 +1,95 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require "file_transfer/version"
         
     | 
| 
       2 
     | 
    
         
            -
            require "file_transfer/file_transfer_handler"
         
     | 
| 
       3 
     | 
    
         
            -
            require "file_transfer/generic"
         
     | 
| 
       4 
     | 
    
         
            -
            require "file_transfer/ftp"
         
     | 
| 
       5 
     | 
    
         
            -
            require "file_transfer/sftp"
         
     | 
| 
       6 
     | 
    
         
            -
            require "file_transfer/ftps"
         
     | 
| 
       7 
     | 
    
         
            -
            require "net/ftp"
         
     | 
| 
       8 
     | 
    
         
            -
            require "net/sftp"
         
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
            ##
         
     | 
| 
       11 
     | 
    
         
            -
            # Module for file exchange from a locale directory to a remote directory and vice versa. Supported protocols are:
         
     | 
| 
       12 
     | 
    
         
            -
            #
         
     | 
| 
       13 
     | 
    
         
            -
            # * FTP
         
     | 
| 
       14 
     | 
    
         
            -
            # * SFTP
         
     | 
| 
       15 
     | 
    
         
            -
            # * FTPS
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
            module FileTransfer
         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
              ##
         
     | 
| 
       20 
     | 
    
         
            -
              # Uploads one or more files to a remote server. To upload files use the locale file paths, not the ruby class File.
         
     | 
| 
       21 
     | 
    
         
            -
              # Types are:
         
     | 
| 
       22 
     | 
    
         
            -
              # * <tt>:ftp</tt> - for FTP file upload
         
     | 
| 
       23 
     | 
    
         
            -
              # * <tt>:ftps</tt> - for FTPS file upload
         
     | 
| 
       24 
     | 
    
         
            -
              # * <tt>:sftp</tt> - for SFTP file upload
         
     | 
| 
       25 
     | 
    
         
            -
              #
         
     | 
| 
       26 
     | 
    
         
            -
              # Options are:
         
     | 
| 
       27 
     | 
    
         
            -
              # * <tt>:username</tt> - Specifies the username for login to the remote server
         
     | 
| 
       28 
     | 
    
         
            -
              # * <tt>:password</tt> - Specifies the password for login to the remote server
         
     | 
| 
       29 
     | 
    
         
            -
              # * <tt>:host</tt> - Specifies the name of the remote server. It could be a DNS name or an IP-Address
         
     | 
| 
       30 
     | 
    
         
            -
              #   these options are not necessary.
         
     | 
| 
       31 
     | 
    
         
            -
              # * <tt>:port</tt> - Specifies the port of the remote server. If the remote server listen on the default port,
         
     | 
| 
       32 
     | 
    
         
            -
              # * <tt>:timeout</tt> - If connection hangs, it is possible to define a timeout in seconds here, where the connection
         
     | 
| 
       33 
     | 
    
         
            -
              #   will be automatically closed.
         
     | 
| 
       34 
     | 
    
         
            -
              #
         
     | 
| 
       35 
     | 
    
         
            -
              # ==Examples
         
     | 
| 
       36 
     | 
    
         
            -
              # <tt>FileTransfer.upload :ftp,
         
     | 
| 
       37 
     | 
    
         
            -
              #       {:username => 'foo', :password => 'bar', :host => 'localhost'}, [
         
     | 
| 
       38 
     | 
    
         
            -
              #       {:from => "/local/1.txt", :to => "/remote/uploads/a_1.txt"},
         
     | 
| 
       39 
     | 
    
         
            -
              #       {:from => "/local/", :to => "/remote/uploads/"},
         
     | 
| 
       40 
     | 
    
         
            -
              #       {:from => "/local/pdf/*.pdf", :to => "/remote/uploads/pdf/"},
         
     | 
| 
       41 
     | 
    
         
            -
              #       {:from => ["/local/1.txt", "/local/2.txt", "/local/txt/*.txt"], :to => "/remote/uploads/txt/"}
         
     | 
| 
       42 
     | 
    
         
            -
              #       ]
         
     | 
| 
       43 
     | 
    
         
            -
              # </tt>
         
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
              def self.upload(type, options, paths)
         
     | 
| 
       46 
     | 
    
         
            -
                handler = FileTransferHandler.new type, options
         
     | 
| 
       47 
     | 
    
         
            -
                result = handler.upload paths
         
     | 
| 
       48 
     | 
    
         
            -
                handler.close
         
     | 
| 
       49 
     | 
    
         
            -
                result
         
     | 
| 
       50 
     | 
    
         
            -
              end
         
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
              # <tt>FileTransfer.download :ftp,
         
     | 
| 
       53 
     | 
    
         
            -
              #       {:username => 'foo', :password => 'bar', :host => 'localhost'}, [
         
     | 
| 
       54 
     | 
    
         
            -
              #       {:from => "/remote/uploads/a_1.txt", :to => "/local/1.txt"},
         
     | 
| 
       55 
     | 
    
         
            -
              #       {:from => "/remote/uploads/pdf/*.pdf", :to => "/local/pdf/"},
         
     | 
| 
       56 
     | 
    
         
            -
              #       {:from => ["/remote/uploads/a_1.txt", "/remote/uploads/a_2.txt", "/remote/uploads/txt/*.txt"], :to => "/local/txt/"}
         
     | 
| 
       57 
     | 
    
         
            -
              #       ]
         
     | 
| 
       58 
     | 
    
         
            -
              # </tt>
         
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
              def self.download(type, options, paths)
         
     | 
| 
       61 
     | 
    
         
            -
                handler = FileTransferHandler.new type, options
         
     | 
| 
       62 
     | 
    
         
            -
                result = handler.download paths
         
     | 
| 
       63 
     | 
    
         
            -
                handler.close
         
     | 
| 
       64 
     | 
    
         
            -
                result
         
     | 
| 
       65 
     | 
    
         
            -
              end
         
     | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
       67 
     | 
    
         
            -
              def self.remove(type, options, paths)
         
     | 
| 
       68 
     | 
    
         
            -
                handler = FileTransferHandler.new type, options
         
     | 
| 
       69 
     | 
    
         
            -
                result = handler.remove paths
         
     | 
| 
       70 
     | 
    
         
            -
                handler.close
         
     | 
| 
       71 
     | 
    
         
            -
                result
         
     | 
| 
       72 
     | 
    
         
            -
              end
         
     | 
| 
       73 
     | 
    
         
            -
             
     | 
| 
       74 
     | 
    
         
            -
              def self.rename(type, options, from_path, to_path)
         
     | 
| 
       75 
     | 
    
         
            -
                handler = FileTransferHandler.new type, options
         
     | 
| 
       76 
     | 
    
         
            -
                result = handler.rename from_path, to_path
         
     | 
| 
       77 
     | 
    
         
            -
                handler.close
         
     | 
| 
       78 
     | 
    
         
            -
                result
         
     | 
| 
       79 
     | 
    
         
            -
              end
         
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
       81 
     | 
    
         
            -
              def self.list(type, options, path)
         
     | 
| 
       82 
     | 
    
         
            -
                handler = FileTransferHandler.new type, options
         
     | 
| 
       83 
     | 
    
         
            -
                result = handler.list path
         
     | 
| 
       84 
     | 
    
         
            -
                handler.close
         
     | 
| 
       85 
     | 
    
         
            -
                result
         
     | 
| 
       86 
     | 
    
         
            -
              end
         
     | 
| 
       87 
     | 
    
         
            -
             
     | 
| 
       88 
     | 
    
         
            -
              def self.exists?(type, options, path)
         
     | 
| 
       89 
     | 
    
         
            -
                handler = FileTransferHandler.new type, options
         
     | 
| 
       90 
     | 
    
         
            -
                result = handler.exists? path
         
     | 
| 
       91 
     | 
    
         
            -
                handler.close
         
     | 
| 
       92 
     | 
    
         
            -
                result
         
     | 
| 
       93 
     | 
    
         
            -
              end
         
     | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
       95 
     | 
    
         
            -
            end
         
     | 
| 
      
 1 
     | 
    
         
            +
            require "file_transfer/version"
         
     | 
| 
      
 2 
     | 
    
         
            +
            require "file_transfer/file_transfer_handler"
         
     | 
| 
      
 3 
     | 
    
         
            +
            require "file_transfer/generic"
         
     | 
| 
      
 4 
     | 
    
         
            +
            require "file_transfer/ftp"
         
     | 
| 
      
 5 
     | 
    
         
            +
            require "file_transfer/sftp"
         
     | 
| 
      
 6 
     | 
    
         
            +
            require "file_transfer/ftps"
         
     | 
| 
      
 7 
     | 
    
         
            +
            require "net/ftp"
         
     | 
| 
      
 8 
     | 
    
         
            +
            require "net/sftp"
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
            ##
         
     | 
| 
      
 11 
     | 
    
         
            +
            # Module for file exchange from a locale directory to a remote directory and vice versa. Supported protocols are:
         
     | 
| 
      
 12 
     | 
    
         
            +
            #
         
     | 
| 
      
 13 
     | 
    
         
            +
            # * FTP
         
     | 
| 
      
 14 
     | 
    
         
            +
            # * SFTP
         
     | 
| 
      
 15 
     | 
    
         
            +
            # * FTPS
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            module FileTransfer
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
              ##
         
     | 
| 
      
 20 
     | 
    
         
            +
              # Uploads one or more files to a remote server. To upload files use the locale file paths, not the ruby class File.
         
     | 
| 
      
 21 
     | 
    
         
            +
              # Types are:
         
     | 
| 
      
 22 
     | 
    
         
            +
              # * <tt>:ftp</tt> - for FTP file upload
         
     | 
| 
      
 23 
     | 
    
         
            +
              # * <tt>:ftps</tt> - for FTPS file upload
         
     | 
| 
      
 24 
     | 
    
         
            +
              # * <tt>:sftp</tt> - for SFTP file upload
         
     | 
| 
      
 25 
     | 
    
         
            +
              #
         
     | 
| 
      
 26 
     | 
    
         
            +
              # Options are:
         
     | 
| 
      
 27 
     | 
    
         
            +
              # * <tt>:username</tt> - Specifies the username for login to the remote server
         
     | 
| 
      
 28 
     | 
    
         
            +
              # * <tt>:password</tt> - Specifies the password for login to the remote server
         
     | 
| 
      
 29 
     | 
    
         
            +
              # * <tt>:host</tt> - Specifies the name of the remote server. It could be a DNS name or an IP-Address
         
     | 
| 
      
 30 
     | 
    
         
            +
              #   these options are not necessary.
         
     | 
| 
      
 31 
     | 
    
         
            +
              # * <tt>:port</tt> - Specifies the port of the remote server. If the remote server listen on the default port,
         
     | 
| 
      
 32 
     | 
    
         
            +
              # * <tt>:timeout</tt> - If connection hangs, it is possible to define a timeout in seconds here, where the connection
         
     | 
| 
      
 33 
     | 
    
         
            +
              #   will be automatically closed.
         
     | 
| 
      
 34 
     | 
    
         
            +
              #
         
     | 
| 
      
 35 
     | 
    
         
            +
              # ==Examples
         
     | 
| 
      
 36 
     | 
    
         
            +
              # <tt>FileTransfer.upload :ftp,
         
     | 
| 
      
 37 
     | 
    
         
            +
              #       {:username => 'foo', :password => 'bar', :host => 'localhost'}, [
         
     | 
| 
      
 38 
     | 
    
         
            +
              #       {:from => "/local/1.txt", :to => "/remote/uploads/a_1.txt"},
         
     | 
| 
      
 39 
     | 
    
         
            +
              #       {:from => "/local/", :to => "/remote/uploads/"},
         
     | 
| 
      
 40 
     | 
    
         
            +
              #       {:from => "/local/pdf/*.pdf", :to => "/remote/uploads/pdf/"},
         
     | 
| 
      
 41 
     | 
    
         
            +
              #       {:from => ["/local/1.txt", "/local/2.txt", "/local/txt/*.txt"], :to => "/remote/uploads/txt/"}
         
     | 
| 
      
 42 
     | 
    
         
            +
              #       ]
         
     | 
| 
      
 43 
     | 
    
         
            +
              # </tt>
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
              def self.upload(type, options, paths)
         
     | 
| 
      
 46 
     | 
    
         
            +
                handler = FileTransferHandler.new type, options
         
     | 
| 
      
 47 
     | 
    
         
            +
                result = handler.upload paths
         
     | 
| 
      
 48 
     | 
    
         
            +
                handler.close
         
     | 
| 
      
 49 
     | 
    
         
            +
                result
         
     | 
| 
      
 50 
     | 
    
         
            +
              end
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
              # <tt>FileTransfer.download :ftp,
         
     | 
| 
      
 53 
     | 
    
         
            +
              #       {:username => 'foo', :password => 'bar', :host => 'localhost'}, [
         
     | 
| 
      
 54 
     | 
    
         
            +
              #       {:from => "/remote/uploads/a_1.txt", :to => "/local/1.txt"},
         
     | 
| 
      
 55 
     | 
    
         
            +
              #       {:from => "/remote/uploads/pdf/*.pdf", :to => "/local/pdf/"},
         
     | 
| 
      
 56 
     | 
    
         
            +
              #       {:from => ["/remote/uploads/a_1.txt", "/remote/uploads/a_2.txt", "/remote/uploads/txt/*.txt"], :to => "/local/txt/"}
         
     | 
| 
      
 57 
     | 
    
         
            +
              #       ]
         
     | 
| 
      
 58 
     | 
    
         
            +
              # </tt>
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
              def self.download(type, options, paths)
         
     | 
| 
      
 61 
     | 
    
         
            +
                handler = FileTransferHandler.new type, options
         
     | 
| 
      
 62 
     | 
    
         
            +
                result = handler.download paths
         
     | 
| 
      
 63 
     | 
    
         
            +
                handler.close
         
     | 
| 
      
 64 
     | 
    
         
            +
                result
         
     | 
| 
      
 65 
     | 
    
         
            +
              end
         
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
      
 67 
     | 
    
         
            +
              def self.remove(type, options, paths)
         
     | 
| 
      
 68 
     | 
    
         
            +
                handler = FileTransferHandler.new type, options
         
     | 
| 
      
 69 
     | 
    
         
            +
                result = handler.remove paths
         
     | 
| 
      
 70 
     | 
    
         
            +
                handler.close
         
     | 
| 
      
 71 
     | 
    
         
            +
                result
         
     | 
| 
      
 72 
     | 
    
         
            +
              end
         
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
      
 74 
     | 
    
         
            +
              def self.rename(type, options, from_path, to_path)
         
     | 
| 
      
 75 
     | 
    
         
            +
                handler = FileTransferHandler.new type, options
         
     | 
| 
      
 76 
     | 
    
         
            +
                result = handler.rename from_path, to_path
         
     | 
| 
      
 77 
     | 
    
         
            +
                handler.close
         
     | 
| 
      
 78 
     | 
    
         
            +
                result
         
     | 
| 
      
 79 
     | 
    
         
            +
              end
         
     | 
| 
      
 80 
     | 
    
         
            +
             
     | 
| 
      
 81 
     | 
    
         
            +
              def self.list(type, options, path)
         
     | 
| 
      
 82 
     | 
    
         
            +
                handler = FileTransferHandler.new type, options
         
     | 
| 
      
 83 
     | 
    
         
            +
                result = handler.list path
         
     | 
| 
      
 84 
     | 
    
         
            +
                handler.close
         
     | 
| 
      
 85 
     | 
    
         
            +
                result
         
     | 
| 
      
 86 
     | 
    
         
            +
              end
         
     | 
| 
      
 87 
     | 
    
         
            +
             
     | 
| 
      
 88 
     | 
    
         
            +
              def self.exists?(type, options, path)
         
     | 
| 
      
 89 
     | 
    
         
            +
                handler = FileTransferHandler.new type, options
         
     | 
| 
      
 90 
     | 
    
         
            +
                result = handler.exists? path
         
     | 
| 
      
 91 
     | 
    
         
            +
                handler.close
         
     | 
| 
      
 92 
     | 
    
         
            +
                result
         
     | 
| 
      
 93 
     | 
    
         
            +
              end
         
     | 
| 
      
 94 
     | 
    
         
            +
             
     | 
| 
      
 95 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -1,152 +1,152 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require "spec_helper"
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            RSpec.configure do |c|
         
     | 
| 
       4 
     | 
    
         
            -
              c.filter_run_excluding :transaction => true
         
     | 
| 
       5 
     | 
    
         
            -
            end
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
            module FileTransfer
         
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
              describe FileTransferHandler do
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
                describe "#_upload", :transaction => true do
         
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
                end
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
                describe "#upload" do
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
                  #it "should return an Array of JPG Files from one Folder" do
         
     | 
| 
       18 
     | 
    
         
            -
                  #  instance = FileTransferHandler.new :ftp, {}
         
     | 
| 
       19 
     | 
    
         
            -
                  #  this_path = File.dirname(__FILE__)
         
     | 
| 
       20 
     | 
    
         
            -
                  #  paths = {:from => ["#{this_path}/../test_files/folder2", "*.jpg"], :to => "/remote_path/"}
         
     | 
| 
       21 
     | 
    
         
            -
                  #  instance.stub(:_upload).and_return(true)
         
     | 
| 
       22 
     | 
    
         
            -
                  #  result = instance.upload(paths)
         
     | 
| 
       23 
     | 
    
         
            -
                  #  Dir.chdir(paths[:from][0])
         
     | 
| 
       24 
     | 
    
         
            -
                  #  result_array = Dir[paths[:from][1]]
         
     | 
| 
       25 
     | 
    
         
            -
                  #  result.should be_kind_of(Array)
         
     | 
| 
       26 
     | 
    
         
            -
                  #  result.should match_array(result_array)
         
     | 
| 
       27 
     | 
    
         
            -
                  #
         
     | 
| 
       28 
     | 
    
         
            -
                  #  puts "--BEGIN OF TEST"
         
     | 
| 
       29 
     | 
    
         
            -
                  #  puts result
         
     | 
| 
       30 
     | 
    
         
            -
                  #  puts "--END OF TEST"
         
     | 
| 
       31 
     | 
    
         
            -
                  #end
         
     | 
| 
       32 
     | 
    
         
            -
                  #
         
     | 
| 
       33 
     | 
    
         
            -
                  #it "should return an Array of JPG Files from all Subfolders incl. Root-Folder" do
         
     | 
| 
       34 
     | 
    
         
            -
                  #  instance = FileTransferHandler.new :ftp, {}
         
     | 
| 
       35 
     | 
    
         
            -
                  #  this_path = File.dirname(__FILE__)
         
     | 
| 
       36 
     | 
    
         
            -
                  #  paths = {:from => ["#{this_path}/../test_files/", "**/*.jpg"], :to => "/remote_path/"}
         
     | 
| 
       37 
     | 
    
         
            -
                  #  instance.stub(:_upload).and_return(true)
         
     | 
| 
       38 
     | 
    
         
            -
                  #  result = instance.upload(paths)
         
     | 
| 
       39 
     | 
    
         
            -
                  #  Dir.chdir(paths[:from][0])
         
     | 
| 
       40 
     | 
    
         
            -
                  #  result_array = Dir[paths[:from][1]]
         
     | 
| 
       41 
     | 
    
         
            -
                  #  result.should be_kind_of(Array)
         
     | 
| 
       42 
     | 
    
         
            -
                  #  result.should match_array(result_array)
         
     | 
| 
       43 
     | 
    
         
            -
                  #
         
     | 
| 
       44 
     | 
    
         
            -
                  #  puts "--BEGIN OF TEST"
         
     | 
| 
       45 
     | 
    
         
            -
                  #  puts result
         
     | 
| 
       46 
     | 
    
         
            -
                  #  puts "--END OF TEST"
         
     | 
| 
       47 
     | 
    
         
            -
                  #end
         
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
                  it "should list from OTTO SFTP" do
         
     | 
| 
       50 
     | 
    
         
            -
                    instance = FileTransferHandler.new :sftp, {
         
     | 
| 
       51 
     | 
    
         
            -
                        :host => "sftp-dmz.otto.de",
         
     | 
| 
       52 
     | 
    
         
            -
                        :username => "eosch",
         
     | 
| 
       53 
     | 
    
         
            -
                        :password => "hot}Orm1",
         
     | 
| 
       54 
     | 
    
         
            -
                        :port => 22
         
     | 
| 
       55 
     | 
    
         
            -
                    }
         
     | 
| 
       56 
     | 
    
         
            -
                    puts instance.list("/").inspect
         
     | 
| 
       57 
     | 
    
         
            -
                  end
         
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
                  it "should upload a test-file to OTTO SFTP" do
         
     | 
| 
       60 
     | 
    
         
            -
                    instance = FileTransferHandler.new :sftp, {
         
     | 
| 
       61 
     | 
    
         
            -
                        :host => "sftp-dmz.otto.de",
         
     | 
| 
       62 
     | 
    
         
            -
                        :username => "eosch",
         
     | 
| 
       63 
     | 
    
         
            -
                        :password => "hot}Orm1",
         
     | 
| 
       64 
     | 
    
         
            -
                        :port => 22
         
     | 
| 
       65 
     | 
    
         
            -
                    }
         
     | 
| 
       66 
     | 
    
         
            -
                    this_path = File.dirname(__FILE__)
         
     | 
| 
       67 
     | 
    
         
            -
                    paths = {:from => "#{this_path}/../test_files/empty_file.csv", :to => "/eosch/in/test/empty_file_1.csv"}
         
     | 
| 
       68 
     | 
    
         
            -
                    result = instance.upload(paths)
         
     | 
| 
       69 
     | 
    
         
            -
                    Dir.chdir("#{this_path}/../test_files/")
         
     | 
| 
       70 
     | 
    
         
            -
                    result_array = Dir["*.csv"]
         
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
     | 
    
         
            -
                    result.should be_kind_of(Array)
         
     | 
| 
       73 
     | 
    
         
            -
                    #result.should match_array(result_array)
         
     | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
       75 
     | 
    
         
            -
                    puts "--BEGIN OF TEST"
         
     | 
| 
       76 
     | 
    
         
            -
                    puts result
         
     | 
| 
       77 
     | 
    
         
            -
                    puts "--END OF TEST"
         
     | 
| 
       78 
     | 
    
         
            -
                  end
         
     | 
| 
       79 
     | 
    
         
            -
             
     | 
| 
       80 
     | 
    
         
            -
                  it "should download the test-file from OTTO SFTP" do
         
     | 
| 
       81 
     | 
    
         
            -
                    instance = FileTransferHandler.new :sftp, {
         
     | 
| 
       82 
     | 
    
         
            -
                        :host => "sftp-dmz.otto.de",
         
     | 
| 
       83 
     | 
    
         
            -
                        :username => "eosch",
         
     | 
| 
       84 
     | 
    
         
            -
                        :password => "hot}Orm1",
         
     | 
| 
       85 
     | 
    
         
            -
                        :port => 22
         
     | 
| 
       86 
     | 
    
         
            -
                    }
         
     | 
| 
       87 
     | 
    
         
            -
                    this_path = File.dirname(__FILE__)
         
     | 
| 
       88 
     | 
    
         
            -
                    paths = {:from => "/eosch/in/test/empty_file_1.csv", :to => "#{this_path}/../test_files/empty_file_from_sftp.csv"}
         
     | 
| 
       89 
     | 
    
         
            -
                    result = instance.download(paths)
         
     | 
| 
       90 
     | 
    
         
            -
                    Dir.chdir("#{this_path}/../test_files/")
         
     | 
| 
       91 
     | 
    
         
            -
                    result_array = Dir["*.csv"]
         
     | 
| 
       92 
     | 
    
         
            -
             
     | 
| 
       93 
     | 
    
         
            -
                    result.should be_kind_of(Array)
         
     | 
| 
       94 
     | 
    
         
            -
                    #result.should match_array(result_array)
         
     | 
| 
       95 
     | 
    
         
            -
             
     | 
| 
       96 
     | 
    
         
            -
                    puts "--BEGIN OF TEST"
         
     | 
| 
       97 
     | 
    
         
            -
                    puts result
         
     | 
| 
       98 
     | 
    
         
            -
                    puts "--END OF TEST"
         
     | 
| 
       99 
     | 
    
         
            -
                  end
         
     | 
| 
       100 
     | 
    
         
            -
             
     | 
| 
       101 
     | 
    
         
            -
                  it "should rename the test-file from OTTO SFTP" do
         
     | 
| 
       102 
     | 
    
         
            -
                    instance = FileTransferHandler.new :sftp, {
         
     | 
| 
       103 
     | 
    
         
            -
                        :host => "sftp-dmz.otto.de",
         
     | 
| 
       104 
     | 
    
         
            -
                        :username => "eosch",
         
     | 
| 
       105 
     | 
    
         
            -
                        :password => "hot}Orm1",
         
     | 
| 
       106 
     | 
    
         
            -
                        :port => 22
         
     | 
| 
       107 
     | 
    
         
            -
                    }
         
     | 
| 
       108 
     | 
    
         
            -
                    result = instance.rename "/eosch/in/test/empty_file_1.csv", "/eosch/in/test/empty_file_1.csv_old"
         
     | 
| 
       109 
     | 
    
         
            -
                  end
         
     | 
| 
       110 
     | 
    
         
            -
             
     | 
| 
       111 
     | 
    
         
            -
                  #it "should return an Array of various Files" do
         
     | 
| 
       112 
     | 
    
         
            -
                  #  instance = FileTransferHandler.new :ftp, {}
         
     | 
| 
       113 
     | 
    
         
            -
                  #  this_path = File.dirname(__FILE__)
         
     | 
| 
       114 
     | 
    
         
            -
                  #  paths = [
         
     | 
| 
       115 
     | 
    
         
            -
                  #    {:from => [
         
     | 
| 
       116 
     | 
    
         
            -
                  #        ["#{this_path}/../test_files/", "**/*.txt"],
         
     | 
| 
       117 
     | 
    
         
            -
                  #        "#{this_path}/../test_files/folder1/"
         
     | 
| 
       118 
     | 
    
         
            -
                  #      ],
         
     | 
| 
       119 
     | 
    
         
            -
                  #      :to => "/remote_path/"
         
     | 
| 
       120 
     | 
    
         
            -
                  #    },
         
     | 
| 
       121 
     | 
    
         
            -
                  #    {:from => ["#{this_path}/../test_files/folder2/", "[jt]*.jpg"], :to => "/remote_path/"}
         
     | 
| 
       122 
     | 
    
         
            -
                  #  ]
         
     | 
| 
       123 
     | 
    
         
            -
                  #
         
     | 
| 
       124 
     | 
    
         
            -
                  #  instance.stub(:_upload).and_return(true)
         
     | 
| 
       125 
     | 
    
         
            -
                  #  result = instance.upload(paths)
         
     | 
| 
       126 
     | 
    
         
            -
                  #
         
     | 
| 
       127 
     | 
    
         
            -
                  #  Dir.chdir(paths[0][:from][0][0])
         
     | 
| 
       128 
     | 
    
         
            -
                  #  result_array = Dir[paths[0][:from][0][1]]
         
     | 
| 
       129 
     | 
    
         
            -
                  #
         
     | 
| 
       130 
     | 
    
         
            -
                  #  Dir.chdir(paths[0][:from][1])
         
     | 
| 
       131 
     | 
    
         
            -
                  #  Dir["*.*"].each do |f|
         
     | 
| 
       132 
     | 
    
         
            -
                  #    result_array.push f
         
     | 
| 
       133 
     | 
    
         
            -
                  #  end
         
     | 
| 
       134 
     | 
    
         
            -
                  #
         
     | 
| 
       135 
     | 
    
         
            -
                  #  Dir.chdir(paths[1][:from][0])
         
     | 
| 
       136 
     | 
    
         
            -
                  #  Dir[paths[1][:from][1]].each do |f|
         
     | 
| 
       137 
     | 
    
         
            -
                  #    result_array.push f
         
     | 
| 
       138 
     | 
    
         
            -
                  #  end
         
     | 
| 
       139 
     | 
    
         
            -
                  #
         
     | 
| 
       140 
     | 
    
         
            -
                  #  result.should be_kind_of(Array)
         
     | 
| 
       141 
     | 
    
         
            -
                  #  result.should match_array(result_array)
         
     | 
| 
       142 
     | 
    
         
            -
                  #
         
     | 
| 
       143 
     | 
    
         
            -
                  #  puts "--BEGIN OF TEST"
         
     | 
| 
       144 
     | 
    
         
            -
                  #  puts result
         
     | 
| 
       145 
     | 
    
         
            -
                  #  puts "--END OF TEST"
         
     | 
| 
       146 
     | 
    
         
            -
                  #end
         
     | 
| 
       147 
     | 
    
         
            -
             
     | 
| 
       148 
     | 
    
         
            -
                end
         
     | 
| 
       149 
     | 
    
         
            -
             
     | 
| 
       150 
     | 
    
         
            -
              end
         
     | 
| 
       151 
     | 
    
         
            -
             
     | 
| 
      
 1 
     | 
    
         
            +
            require "spec_helper"
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            RSpec.configure do |c|
         
     | 
| 
      
 4 
     | 
    
         
            +
              c.filter_run_excluding :transaction => true
         
     | 
| 
      
 5 
     | 
    
         
            +
            end
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            module FileTransfer
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
              describe FileTransferHandler do
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                describe "#_upload", :transaction => true do
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                describe "#upload" do
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                  #it "should return an Array of JPG Files from one Folder" do
         
     | 
| 
      
 18 
     | 
    
         
            +
                  #  instance = FileTransferHandler.new :ftp, {}
         
     | 
| 
      
 19 
     | 
    
         
            +
                  #  this_path = File.dirname(__FILE__)
         
     | 
| 
      
 20 
     | 
    
         
            +
                  #  paths = {:from => ["#{this_path}/../test_files/folder2", "*.jpg"], :to => "/remote_path/"}
         
     | 
| 
      
 21 
     | 
    
         
            +
                  #  instance.stub(:_upload).and_return(true)
         
     | 
| 
      
 22 
     | 
    
         
            +
                  #  result = instance.upload(paths)
         
     | 
| 
      
 23 
     | 
    
         
            +
                  #  Dir.chdir(paths[:from][0])
         
     | 
| 
      
 24 
     | 
    
         
            +
                  #  result_array = Dir[paths[:from][1]]
         
     | 
| 
      
 25 
     | 
    
         
            +
                  #  result.should be_kind_of(Array)
         
     | 
| 
      
 26 
     | 
    
         
            +
                  #  result.should match_array(result_array)
         
     | 
| 
      
 27 
     | 
    
         
            +
                  #
         
     | 
| 
      
 28 
     | 
    
         
            +
                  #  puts "--BEGIN OF TEST"
         
     | 
| 
      
 29 
     | 
    
         
            +
                  #  puts result
         
     | 
| 
      
 30 
     | 
    
         
            +
                  #  puts "--END OF TEST"
         
     | 
| 
      
 31 
     | 
    
         
            +
                  #end
         
     | 
| 
      
 32 
     | 
    
         
            +
                  #
         
     | 
| 
      
 33 
     | 
    
         
            +
                  #it "should return an Array of JPG Files from all Subfolders incl. Root-Folder" do
         
     | 
| 
      
 34 
     | 
    
         
            +
                  #  instance = FileTransferHandler.new :ftp, {}
         
     | 
| 
      
 35 
     | 
    
         
            +
                  #  this_path = File.dirname(__FILE__)
         
     | 
| 
      
 36 
     | 
    
         
            +
                  #  paths = {:from => ["#{this_path}/../test_files/", "**/*.jpg"], :to => "/remote_path/"}
         
     | 
| 
      
 37 
     | 
    
         
            +
                  #  instance.stub(:_upload).and_return(true)
         
     | 
| 
      
 38 
     | 
    
         
            +
                  #  result = instance.upload(paths)
         
     | 
| 
      
 39 
     | 
    
         
            +
                  #  Dir.chdir(paths[:from][0])
         
     | 
| 
      
 40 
     | 
    
         
            +
                  #  result_array = Dir[paths[:from][1]]
         
     | 
| 
      
 41 
     | 
    
         
            +
                  #  result.should be_kind_of(Array)
         
     | 
| 
      
 42 
     | 
    
         
            +
                  #  result.should match_array(result_array)
         
     | 
| 
      
 43 
     | 
    
         
            +
                  #
         
     | 
| 
      
 44 
     | 
    
         
            +
                  #  puts "--BEGIN OF TEST"
         
     | 
| 
      
 45 
     | 
    
         
            +
                  #  puts result
         
     | 
| 
      
 46 
     | 
    
         
            +
                  #  puts "--END OF TEST"
         
     | 
| 
      
 47 
     | 
    
         
            +
                  #end
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
                  it "should list from OTTO SFTP" do
         
     | 
| 
      
 50 
     | 
    
         
            +
                    instance = FileTransferHandler.new :sftp, {
         
     | 
| 
      
 51 
     | 
    
         
            +
                        :host => "sftp-dmz.otto.de",
         
     | 
| 
      
 52 
     | 
    
         
            +
                        :username => "eosch",
         
     | 
| 
      
 53 
     | 
    
         
            +
                        :password => "hot}Orm1",
         
     | 
| 
      
 54 
     | 
    
         
            +
                        :port => 22
         
     | 
| 
      
 55 
     | 
    
         
            +
                    }
         
     | 
| 
      
 56 
     | 
    
         
            +
                    puts instance.list("/").inspect
         
     | 
| 
      
 57 
     | 
    
         
            +
                  end
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
                  it "should upload a test-file to OTTO SFTP" do
         
     | 
| 
      
 60 
     | 
    
         
            +
                    instance = FileTransferHandler.new :sftp, {
         
     | 
| 
      
 61 
     | 
    
         
            +
                        :host => "sftp-dmz.otto.de",
         
     | 
| 
      
 62 
     | 
    
         
            +
                        :username => "eosch",
         
     | 
| 
      
 63 
     | 
    
         
            +
                        :password => "hot}Orm1",
         
     | 
| 
      
 64 
     | 
    
         
            +
                        :port => 22
         
     | 
| 
      
 65 
     | 
    
         
            +
                    }
         
     | 
| 
      
 66 
     | 
    
         
            +
                    this_path = File.dirname(__FILE__)
         
     | 
| 
      
 67 
     | 
    
         
            +
                    paths = {:from => "#{this_path}/../test_files/empty_file.csv", :to => "/eosch/in/test/empty_file_1.csv"}
         
     | 
| 
      
 68 
     | 
    
         
            +
                    result = instance.upload(paths)
         
     | 
| 
      
 69 
     | 
    
         
            +
                    Dir.chdir("#{this_path}/../test_files/")
         
     | 
| 
      
 70 
     | 
    
         
            +
                    result_array = Dir["*.csv"]
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
                    result.should be_kind_of(Array)
         
     | 
| 
      
 73 
     | 
    
         
            +
                    #result.should match_array(result_array)
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
                    puts "--BEGIN OF TEST"
         
     | 
| 
      
 76 
     | 
    
         
            +
                    puts result
         
     | 
| 
      
 77 
     | 
    
         
            +
                    puts "--END OF TEST"
         
     | 
| 
      
 78 
     | 
    
         
            +
                  end
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
                  it "should download the test-file from OTTO SFTP" do
         
     | 
| 
      
 81 
     | 
    
         
            +
                    instance = FileTransferHandler.new :sftp, {
         
     | 
| 
      
 82 
     | 
    
         
            +
                        :host => "sftp-dmz.otto.de",
         
     | 
| 
      
 83 
     | 
    
         
            +
                        :username => "eosch",
         
     | 
| 
      
 84 
     | 
    
         
            +
                        :password => "hot}Orm1",
         
     | 
| 
      
 85 
     | 
    
         
            +
                        :port => 22
         
     | 
| 
      
 86 
     | 
    
         
            +
                    }
         
     | 
| 
      
 87 
     | 
    
         
            +
                    this_path = File.dirname(__FILE__)
         
     | 
| 
      
 88 
     | 
    
         
            +
                    paths = {:from => "/eosch/in/test/empty_file_1.csv", :to => "#{this_path}/../test_files/empty_file_from_sftp.csv"}
         
     | 
| 
      
 89 
     | 
    
         
            +
                    result = instance.download(paths)
         
     | 
| 
      
 90 
     | 
    
         
            +
                    Dir.chdir("#{this_path}/../test_files/")
         
     | 
| 
      
 91 
     | 
    
         
            +
                    result_array = Dir["*.csv"]
         
     | 
| 
      
 92 
     | 
    
         
            +
             
     | 
| 
      
 93 
     | 
    
         
            +
                    result.should be_kind_of(Array)
         
     | 
| 
      
 94 
     | 
    
         
            +
                    #result.should match_array(result_array)
         
     | 
| 
      
 95 
     | 
    
         
            +
             
     | 
| 
      
 96 
     | 
    
         
            +
                    puts "--BEGIN OF TEST"
         
     | 
| 
      
 97 
     | 
    
         
            +
                    puts result
         
     | 
| 
      
 98 
     | 
    
         
            +
                    puts "--END OF TEST"
         
     | 
| 
      
 99 
     | 
    
         
            +
                  end
         
     | 
| 
      
 100 
     | 
    
         
            +
             
     | 
| 
      
 101 
     | 
    
         
            +
                  it "should rename the test-file from OTTO SFTP" do
         
     | 
| 
      
 102 
     | 
    
         
            +
                    instance = FileTransferHandler.new :sftp, {
         
     | 
| 
      
 103 
     | 
    
         
            +
                        :host => "sftp-dmz.otto.de",
         
     | 
| 
      
 104 
     | 
    
         
            +
                        :username => "eosch",
         
     | 
| 
      
 105 
     | 
    
         
            +
                        :password => "hot}Orm1",
         
     | 
| 
      
 106 
     | 
    
         
            +
                        :port => 22
         
     | 
| 
      
 107 
     | 
    
         
            +
                    }
         
     | 
| 
      
 108 
     | 
    
         
            +
                    result = instance.rename "/eosch/in/test/empty_file_1.csv", "/eosch/in/test/empty_file_1.csv_old"
         
     | 
| 
      
 109 
     | 
    
         
            +
                  end
         
     | 
| 
      
 110 
     | 
    
         
            +
             
     | 
| 
      
 111 
     | 
    
         
            +
                  #it "should return an Array of various Files" do
         
     | 
| 
      
 112 
     | 
    
         
            +
                  #  instance = FileTransferHandler.new :ftp, {}
         
     | 
| 
      
 113 
     | 
    
         
            +
                  #  this_path = File.dirname(__FILE__)
         
     | 
| 
      
 114 
     | 
    
         
            +
                  #  paths = [
         
     | 
| 
      
 115 
     | 
    
         
            +
                  #    {:from => [
         
     | 
| 
      
 116 
     | 
    
         
            +
                  #        ["#{this_path}/../test_files/", "**/*.txt"],
         
     | 
| 
      
 117 
     | 
    
         
            +
                  #        "#{this_path}/../test_files/folder1/"
         
     | 
| 
      
 118 
     | 
    
         
            +
                  #      ],
         
     | 
| 
      
 119 
     | 
    
         
            +
                  #      :to => "/remote_path/"
         
     | 
| 
      
 120 
     | 
    
         
            +
                  #    },
         
     | 
| 
      
 121 
     | 
    
         
            +
                  #    {:from => ["#{this_path}/../test_files/folder2/", "[jt]*.jpg"], :to => "/remote_path/"}
         
     | 
| 
      
 122 
     | 
    
         
            +
                  #  ]
         
     | 
| 
      
 123 
     | 
    
         
            +
                  #
         
     | 
| 
      
 124 
     | 
    
         
            +
                  #  instance.stub(:_upload).and_return(true)
         
     | 
| 
      
 125 
     | 
    
         
            +
                  #  result = instance.upload(paths)
         
     | 
| 
      
 126 
     | 
    
         
            +
                  #
         
     | 
| 
      
 127 
     | 
    
         
            +
                  #  Dir.chdir(paths[0][:from][0][0])
         
     | 
| 
      
 128 
     | 
    
         
            +
                  #  result_array = Dir[paths[0][:from][0][1]]
         
     | 
| 
      
 129 
     | 
    
         
            +
                  #
         
     | 
| 
      
 130 
     | 
    
         
            +
                  #  Dir.chdir(paths[0][:from][1])
         
     | 
| 
      
 131 
     | 
    
         
            +
                  #  Dir["*.*"].each do |f|
         
     | 
| 
      
 132 
     | 
    
         
            +
                  #    result_array.push f
         
     | 
| 
      
 133 
     | 
    
         
            +
                  #  end
         
     | 
| 
      
 134 
     | 
    
         
            +
                  #
         
     | 
| 
      
 135 
     | 
    
         
            +
                  #  Dir.chdir(paths[1][:from][0])
         
     | 
| 
      
 136 
     | 
    
         
            +
                  #  Dir[paths[1][:from][1]].each do |f|
         
     | 
| 
      
 137 
     | 
    
         
            +
                  #    result_array.push f
         
     | 
| 
      
 138 
     | 
    
         
            +
                  #  end
         
     | 
| 
      
 139 
     | 
    
         
            +
                  #
         
     | 
| 
      
 140 
     | 
    
         
            +
                  #  result.should be_kind_of(Array)
         
     | 
| 
      
 141 
     | 
    
         
            +
                  #  result.should match_array(result_array)
         
     | 
| 
      
 142 
     | 
    
         
            +
                  #
         
     | 
| 
      
 143 
     | 
    
         
            +
                  #  puts "--BEGIN OF TEST"
         
     | 
| 
      
 144 
     | 
    
         
            +
                  #  puts result
         
     | 
| 
      
 145 
     | 
    
         
            +
                  #  puts "--END OF TEST"
         
     | 
| 
      
 146 
     | 
    
         
            +
                  #end
         
     | 
| 
      
 147 
     | 
    
         
            +
             
     | 
| 
      
 148 
     | 
    
         
            +
                end
         
     | 
| 
      
 149 
     | 
    
         
            +
             
     | 
| 
      
 150 
     | 
    
         
            +
              end
         
     | 
| 
      
 151 
     | 
    
         
            +
             
     | 
| 
       152 
152 
     | 
    
         
             
            end
         
     | 
| 
         @@ -0,0 +1,66 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module FileTransfer
         
     | 
| 
      
 4 
     | 
    
         
            +
              describe Generic do
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
                describe '.new' do
         
     | 
| 
      
 7 
     | 
    
         
            +
                  context 'when options are empty' do
         
     | 
| 
      
 8 
     | 
    
         
            +
                    let(:generic) { Generic.new }
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                    it 'sets default host to localhost' do
         
     | 
| 
      
 11 
     | 
    
         
            +
                      expect(generic.host).to eq('localhost')
         
     | 
| 
      
 12 
     | 
    
         
            +
                    end
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                    it 'sets default username to anonymous' do
         
     | 
| 
      
 15 
     | 
    
         
            +
                      expect(generic.username).to eq('anonymous')
         
     | 
| 
      
 16 
     | 
    
         
            +
                    end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                    it 'sets default password to empty string' do
         
     | 
| 
      
 19 
     | 
    
         
            +
                      expect(generic.password).to eq('')
         
     | 
| 
      
 20 
     | 
    
         
            +
                    end
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                    it 'sets default keys to empty array' do
         
     | 
| 
      
 23 
     | 
    
         
            +
                      expect(generic.keys).to eq([])
         
     | 
| 
      
 24 
     | 
    
         
            +
                    end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                    it 'sets default port to 21' do
         
     | 
| 
      
 27 
     | 
    
         
            +
                      expect(generic.port).to eq(21)
         
     | 
| 
      
 28 
     | 
    
         
            +
                    end
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                    it 'sets default timeout to 300' do
         
     | 
| 
      
 31 
     | 
    
         
            +
                      expect(generic.timeout_seconds).to eq(300)
         
     | 
| 
      
 32 
     | 
    
         
            +
                    end
         
     | 
| 
      
 33 
     | 
    
         
            +
                  end
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                  context 'when options are defined' do
         
     | 
| 
      
 36 
     | 
    
         
            +
                    before do
         
     | 
| 
      
 37 
     | 
    
         
            +
                      @generic = Generic.new(:host => 'test.com', :username => 'test_usr', :password => 'test_pw', :keys => 'test.pk', :port => 22, :timeout => 500)
         
     | 
| 
      
 38 
     | 
    
         
            +
                    end
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                    it 'sets host to options[:host]' do
         
     | 
| 
      
 41 
     | 
    
         
            +
                      expect(@generic.host).to eq('test.com')
         
     | 
| 
      
 42 
     | 
    
         
            +
                    end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                    it 'sets username to options[:username]' do
         
     | 
| 
      
 45 
     | 
    
         
            +
                      expect(@generic.username).to eq('test_usr')
         
     | 
| 
      
 46 
     | 
    
         
            +
                    end
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
                    it 'sets password to options[:password]' do
         
     | 
| 
      
 49 
     | 
    
         
            +
                      expect(@generic.password).to eq('test_pw')
         
     | 
| 
      
 50 
     | 
    
         
            +
                    end
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
                    it 'sets keys to options[:keys]' do
         
     | 
| 
      
 53 
     | 
    
         
            +
                      expect(@generic.keys).to eq(%w(test.pk))
         
     | 
| 
      
 54 
     | 
    
         
            +
                    end
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
                    it 'sets port to options[:port]' do
         
     | 
| 
      
 57 
     | 
    
         
            +
                      expect(@generic.port).to eq(22)
         
     | 
| 
      
 58 
     | 
    
         
            +
                    end
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
                    it 'sets timeout to options[:timeout]' do
         
     | 
| 
      
 61 
     | 
    
         
            +
                      expect(@generic.timeout_seconds).to eq(500)
         
     | 
| 
      
 62 
     | 
    
         
            +
                    end
         
     | 
| 
      
 63 
     | 
    
         
            +
                  end
         
     | 
| 
      
 64 
     | 
    
         
            +
                end
         
     | 
| 
      
 65 
     | 
    
         
            +
              end
         
     | 
| 
      
 66 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,22 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module FileTransfer
         
     | 
| 
      
 4 
     | 
    
         
            +
              describe Sftp do
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
                describe '.new' do
         
     | 
| 
      
 7 
     | 
    
         
            +
                  context 'when port is defined in options parameter' do
         
     | 
| 
      
 8 
     | 
    
         
            +
                    it 'sets port from options' do
         
     | 
| 
      
 9 
     | 
    
         
            +
                      sftp = Sftp.new :port => 23
         
     | 
| 
      
 10 
     | 
    
         
            +
                      expect(sftp.port).to eq(23)
         
     | 
| 
      
 11 
     | 
    
         
            +
                    end
         
     | 
| 
      
 12 
     | 
    
         
            +
                  end
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                  context 'when no port is defined in options parameter' do
         
     | 
| 
      
 15 
     | 
    
         
            +
                    it 'sets default port 22' do
         
     | 
| 
      
 16 
     | 
    
         
            +
                      sftp = Sftp.new
         
     | 
| 
      
 17 
     | 
    
         
            +
                      expect(sftp.port).to be(22)
         
     | 
| 
      
 18 
     | 
    
         
            +
                    end
         
     | 
| 
      
 19 
     | 
    
         
            +
                  end
         
     | 
| 
      
 20 
     | 
    
         
            +
                end
         
     | 
| 
      
 21 
     | 
    
         
            +
              end
         
     | 
| 
      
 22 
     | 
    
         
            +
            end
         
     |