Method: FileTransfer.upload

Defined in:
lib/file_transfer.rb

.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

  • :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>



43
44
45
46
47
48
# File 'lib/file_transfer.rb', line 43

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