Module: FileTransfer

Defined in:
lib/file_transfer.rb,
lib/file_transfer/ftp.rb,
lib/file_transfer/ftps.rb,
lib/file_transfer/sftp.rb,
lib/file_transfer/generic.rb,
lib/file_transfer/version.rb,
lib/file_transfer/file_transfer_handler.rb

Overview

:nodoc:

Defined Under Namespace

Classes: FileTransferHandler, Ftp, Ftps, Generic, Sftp

Constant Summary collapse

VERSION =

:nodoc:

"0.0.6"

Class Method Summary collapse

Class Method Details

.download(type, options, paths) ⇒ Object

<tt>FileTransfer.download :ftp,

{:username => 'foo', :password => 'bar', :host => 'localhost'}, [
{:from => "/remote/uploads/a_1.txt", :to => "/local/1.txt"},
{:from => "/remote/uploads/pdf/*.pdf", :to => "/local/pdf/"},
{:from => ["/remote/uploads/a_1.txt", "/remote/uploads/a_2.txt", "/remote/uploads/txt/*.txt"], :to => "/local/txt/"}
]

</tt>



60
61
62
63
64
65
# File 'lib/file_transfer.rb', line 60

def self.download(type, options, paths)
  handler = FileTransferHandler.new type, options
  result = handler.download paths
  handler.close
  result
end

.exists?(type, options, path) ⇒ Boolean

Returns:

  • (Boolean)


81
82
83
84
85
86
# File 'lib/file_transfer.rb', line 81

def self.exists?(type, options, path)
  handler = FileTransferHandler.new type, options
  result = handler.exists? path
  handler.close
  result
end

.list(type, options, path) ⇒ Object



74
75
76
77
78
79
# File 'lib/file_transfer.rb', line 74

def self.list(type, options, path)
  handler = FileTransferHandler.new type, options
  result = handler.list path
  handler.close
  result
end

.remove(type, options, paths) ⇒ Object



67
68
69
70
71
72
# File 'lib/file_transfer.rb', line 67

def self.remove(type, options, paths)
  handler = FileTransferHandler.new type, options
  result = handler.remove paths
  handler.close
  result
end

.upload(type, options, paths) ⇒ Object

Uploads one or more files to a remote server. To upload files use the locale file paths, not the ruby class File. Types are:

  • :ftp - for FTP file upload

  • :ftps - for FTPS file upload

  • :sftp - for SFTP file upload

Options are:

  • :username - Specifies the username for login to the remote server

  • :password - Specifies the password for login to the remote server

  • :host - Specifies the name of the remote server. It could be a DNS name or an IP-Address these options are not necessary.

  • :port - Specifies the port of the remote server. If the remote server listen on the default port,

  • :timeout - If connection hangs, it is possible to define a timeout in seconds here, where the connection will be automatically closed.

Examples

<tt>FileTransfer.upload :ftp,

{:username => 'foo', :password => 'bar', :host => 'localhost'}, [
{:from => "/local/1.txt", :to => "/remote/uploads/a_1.txt"},
{:from => "/local/", :to => "/remote/uploads/"},
{:from => "/local/pdf/*.pdf", :to => "/remote/uploads/pdf/"},
{:from => ["/local/1.txt", "/local/2.txt", "/local/txt/*.txt"], :to => "/remote/uploads/txt/"}
]

</tt>



45
46
47
48
49
50
# File 'lib/file_transfer.rb', line 45

def self.upload(type, options, paths)
  handler = FileTransferHandler.new type, options
  result = handler.upload paths
  handler.close
  result
end