Skip to content

bradleyprice/file_transfer_mixin

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

== FileTransferMixin ==
FileTransferMixin is a module that you can include in a library.  It will support various mechanisms long-term, but
for now is focused on SFTP servers.

It provides the following methods for now:

- sftp_send(key, remote_location, local_file_path)
- sftp_fetch(key, remote_path, local_path)
- sftp_move(key, original_remote_path, new_remote_path)
- sftp_block(key)

- It expects an ENV variable named FILE_TRANSFER_MIXIN_CONFIG_PATH to be set.
- It expects a yml configuration file in FILE_TRANSFER_MIXIN_CONFIG_PATH that looks like the following:

:development: 
  :sftp: 
    :some_key: 
      :server: 127.0.0.1
      :username: user
      :password: pass
:test: {}

:production: {}

Then in a class, you would deal with it thusly:

class SomeClass
  include FileTransferMixin

  # Some method that uploads a file
  def some_method
    sftp_send(:some_key, remote_path, local_path)
  end

  # Some method that fetches a file
  def fetch_method
    sftp_fetch(:some_key, remote_path, local_path)
  end

  # Some method that moves a file
  def move_method
    sftp_move(:some_key, original_remote_path, new_remote_path)
  end

  # Some method that otherwise uses Net::SFTP commands but still uses our config block
  def sftp_detailed_method
    sftp_block(:some_key) do |ftp|
      ftp.rename!('foo', 'bar')
    end
  end
end

== Motivation ==
We have quite a few libraries that interact with remote SFTP servers, and inevitably they share massive swathes of code
that should be unnecessary.  This intends to be a mixin to make the easy things extremely easy.

About

File Transfer Mixin - make it easy to send and fetch files from a ruby project. Just SFTP for now.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 100.0%